EuroAssembler Index Manual Download Source Macros


Sitemap Links Forum Tests Projects

tmac64.htm

This program is designated for demonstration and testing of some macros defined in libraries sort64.htm and cpuext64.htm : LodD, StoD, StoH, StripSpaces, ShellSort.

Format
PE 64bit
Platform
MS Windows 64bit
Build
euroasm tmac64.htm
Run
tmac64
See also
tmac16.htm, tmac32.htm.
       EUROASM UNICODE=Off,DumpWidth=34,CPU=X64
tmac64 PROGRAM Format=PE,Width=64,IconFile=,Entry=Main:
        INCLUDE winabi.htm, cpuext%^WIDTH.htm, sort%^WIDTH.htm
Main:   PROC
          StdOutput ="This program %^PROGRAM will test macros from EuroAssembler libraries",Eol=Yes
          StdOutput ="cpuext%^WIDTH.htm, sort%^WIDTH.htm.",Eol=Yes
          StdOutput ="Enter one or more comma-separated signed decimal integer numbers",Eol=Yes
          StdOutput =" in the range -9223372036854775808..+9223372036854775807. , for instance",Eol=Yes
          StdOutput =" 12345, -12,0,-2147483648, +2147483647,987654321",Eol=Yes
          StdOutput ="-------------------------------------------------",Eol=Yes
          StdInput  Raw
          MOV RDI,Raw
          MOV RSI,RDI
          MOV ECX,SIZE# Inp
          MOV AL,','
          REPNE SCASB
          SUB RDI,RSI
          StripSpaces RSI,RDI
          MOV RCX,RDI
          MOV RDI,Inp
          REP MOVSB
          StdOutput ="The first entered number:",Eol=Yes
          StdOutput Inp, Size=RDI,Eol=Yes
          StdOutput ="Conversion from decimal to binary and back with macros LodD and StoD:",Eol=Yes
          LodD Inp
          JC .Abort:
          MOV [Bin],RAX
          StoD Dec
          JC .Abort:
          StdOutput Dec,Eol=Yes
          StdOutput ="Conversion from binary to hexadecimal with macro StoH Align=Left:",Eol=Yes
          MOV RAX,[Bin]
          StoH Hex,Align=Left
          JC .Abort:
          StdOutput ="0x",Hex,Eol=Yes
          StdOutput ="Conversion from binary to hexadecimal with macro StoH Align=Right,Size=16:",Eol=Yes
          MOV RAX,[Bin]
          StoH Hex,Align=Right,Size=16
          JC .Abort:
          StdOutput ="0x",Hex,Eol=Yes
          MOV ESI,Raw
          MOV ECX,SIZE# Raw
          StripSpaces RSI,RCX
          StdOutput ="Entered array of numbers:",Eol=Yes
          StdOutput RSI,Size=RCX,Eol=Yes
          LEA RDX,[RSI+RCX]    ; Stripped array is now at RSI..RDX.
          SUB EBX,EBX          ; EBX will keep the number of entered numbers.
          MOV RDI,Tab          ; Loaded numbers will be stored to Tab.
          DEC RSI
.50:      INC RSI
.60:      CMP RSI,RDX          ; Find the next number (it begins with sign or digit).
          JNB .80:             ; End of list.
          LODSB
          CMP AL,'+'
          JE .70:
          CMP AL,'-'
          JE .70:
          CMP AL,'0'
          JB .60:
          CMP AL,'9'
          JA .60:
.70:      DEC RSI
          LodD RSI
          JC .50:              ; Ignore numbers with wrong syntax.
          STOSQ
          INC EBX
          JMP .60:
.80:      StdOutput ="Unsorted array of entered numbers:",Eol=Yes
          CALL .PrintTab:
          ShellSort Tab, RBX, 8, .Ascending:
          StdOutput ="Sorted ascending array of entered numbers:",Eol=Yes
          CALL .PrintTab:
          ShellSort Tab, RBX, 8, .Descending:
          StdOutput ="Sorted descending array of entered numbers:",Eol=Yes
          CALL .PrintTab:
.End:     TerminateProgram
.Abort:   StdOutput Eol=Yes
          StdOutput =B"Aborted, macro returned CF.",Eol=Yes
          TerminateProgram, Errorlevel=8

.Ascending: PROC  ; Sort callback for comparing two signed integers at ESI,EDI.
             MOV RAX,[RSI]
             MOV RDX,[RDI]
             CMP RDX,RAX
             CLC
             JNL .Done:    ; Jump if both records are in order. No carry.
             MOV [RSI],RDX ; Otherwise swap them and return CF.
             MOV [RDI],RAX
             STC
.Done:       RET
            ENDP .Ascending:

.Descending:PROC  ; Sort callback for comparing two signed integers at ESI,EDI.
             MOV RAX,[RSI]
             MOV RDX,[RDI]
             CMP RDX,RAX
             CLC
             JNG .Done:    ; Jump if both records are in order. No carry.
             MOV [RSI],RDX ; Otherwise swap them and return CF.
             MOV [RDI],RAX
             STC
.Done:       RET
            ENDP .Descending:

.PrintTab:  PROC ; Display EBX numbers in Tab.
             MOV RCX,RBX
             MOV RSI,Tab
.Next:       LODSQ
             StoD Dec
             MOV AX,','
             STOSW       ; Terminate the decimal number with comma and NUL.
             StdOutput Dec
             LOOP .Next:
             StdOutput Eol=Yes
             RET
            ENDP .PrintTab:
        ENDP Main:

Raw:  DB 128*BYTE 0  ; Entered array of decimal numbers.
Inp:  DB 32*BYTE 0   ; The first number, stripped from white spaces.
Dec:  DB 32*BYTE 0   ; The first number in decimal notation.
Hex:  DB 16*BYTE 0   ; The first number in hexdecimal notation.
      DB 0           ; Zero terminator.
Bin:  DQ QWORD       ; The first entered number in binary form.
Tab:  DQ 128*QWORD   ; Table of entered numbers in binary form.
    ENDPROGRAM tmac64

▲Back to the top▲