Author Topic: Application Title Prompt  (Read 13086 times)

Offline TightCoderEx

  • Full Member
  • **
  • Posts: 103
Application Title Prompt
« on: June 06, 2012, 01:54:37 AM »
Where a function is only called once or maybe a few times, I choose space over speed.  I also try to engineer data section so those strings only used once can then become a miscellaneous buffer instead of in .const and then becoming dead space.

Code: [Select]
  Temp          equ     $
        NmePrompt     db      10, 9, '[ ] - ', 0
        NmeQuery      db      10, 10, 'Please select [ A - '
        MaxQuery      db      '  ] ', 0             
        NoFile        db      9, 'You must specify a file in command line', 0
        Confirm       db      'Processing ', 0
  TempSize      equ     $ - Temp
 
  SignOff       db      10, 10, 9, '*** DONE ***', 10, 0

As application develops Temp becomes larger than its present 89 bytes, but it is space that can be utilised later with
a little more permanency than stack. ShowTitle needs 96 bytes for characters and 3 for double linefeed / null combination. A space of 104 though keeps stack qword aligned.

Code: [Select]
; * - * - * - * - * - * - * - * - * - * - * - * - * - * - * - * - * - * - * - * - * - * - * -
; Display applications primary prompt

;       ENTRY:  Nothing

;       LEAVE:  RAX - RCX - RDX modified
;                                                                              5EH = 94 Bytes
; -------------------------------------------------------------------------------------------

  ShowTitle     push    rsi
                push    rdi
                enter   104, 0                  ; Frame to hold line
 
        ; Top bar of title prompt is a series of 96 equal signs.
       
                mov      al, '='
                call    InitFrame
                mov     word [rbp - 8], 10      ; Linefeed / Null combination
                mov     rsi, rsp
                call    Console
       
        ; Calculate how many spaces are required to position title string in center of screen
       
                mov     rcx, rax                ; Move size of display area
                sub      cl, .PmtSize           ; Subtract size of string
                shr      cl, 1                  ; (Display-Size) / 2
                mov      al, ' '
                call    FillMem
                add     rcx, rsi
                mov     byte [rcx], 0           ; Set terminator
                call    Console
               
                mov     rsi, .Prompt
                call    Console
                                 
        ; Bottom bar of title prompt is a series of 96 minus signs with double linefeed
       
                mov      al, '-'
                call    InitFrame
                mov     dword [rbp - 8], 0x0a0a ; double linefeed / Null combination
                mov     rsi, rsp
                call    Console
               
                leave
                pop     rdi
                pop     rsi
                ret
               
  .Prompt       db      'Spectrum Business / Personal Record Keeping', 10, 0
  .PmtSize      equ     $ - .Prompt             ; = 45 bytes


Additional to the size of .Prompt to declare the same functionality in .const would require 98 bytes first line 30 to tab prompt to proper position to centre and 99 for bottom line.  This would be 227 bytes of dead object versus 94 that routine requires.

FillMem & InitFrame can be viewed @ http://forum.nasm.us/index.php?topic=1388.0
                   Console                         http://forum.nasm.us/index.php?topic=1379.0

NOTE: As anything declared in .const winds up in .text anyway, permanent strings are embedded in code so they are closer to where they're being used and easier to find as I'm not using an IDE.
« Last Edit: June 06, 2012, 02:00:28 AM by TightCoderEx »