EuroAssembler Index Manual Download Source Macros


Sitemap Links Forum Tests Projects

tmac32.htm

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

Format
PE 32bit
Platform
MS Windows
Build
euroasm tmac32.htm
Run
tmac32
See also
tmac16.htm, tmac64.htm.
       EUROASM UNICODE=Off
tmac32 PROGRAM Format=PE,Width=32,IconFile=,Entry=Main:
        INCLUDE winapi.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 -2147483648..+2147483647, for instance",Eol=Yes
          StdOutput =" 12345, -12,0,-2147483648, +2147483647,987654321",Eol=Yes
          StdOutput ="-------------------------------------------------",Eol=Yes
          StdInput  Raw
          MOV EDI,Raw
          MOV ESI,EDI
          MOV ECX,SIZE# Inp
          MOV AL,','
          REPNE SCASB
          SUB EDI,ESI
          StripSpaces ESI,EDI
          MOV ECX,EDI
          MOV EDI,Inp
          REP MOVSB
          StdOutput ="The first entered number:",Eol=Yes
          StdOutput Inp, Size=EDI,Eol=Yes
          StdOutput ="Conversion from decimal to binary and back with macros LodD and StoD:",Eol=Yes
          LodD Inp
          JC .Abort:
          MOV [Bin],EAX
          StoD Dec
          JC .Abort:
          StdOutput Dec,Eol=Yes
          StdOutput ="Conversion from binary to hexadecimal with macro StoH Align=Left:",Eol=Yes
          MOV EAX,[Bin]
          StoH Hex,Align=Left
          JC .Abort:
          StdOutput ="0x",Hex,Eol=Yes
          StdOutput ="Conversion from binary to hexadecimal with macro StoH Align=Right,Size=8:",Eol=Yes
          MOV EAX,[Bin]
          StoH Hex,Align=Right,Size=8
          JC .Abort:
          StdOutput ="0x",Hex,Eol=Yes
          MOV ESI,Raw
          MOV ECX,SIZE# Raw
          StripSpaces ESI,ECX
          StdOutput ="Entered array of numbers:",Eol=Yes
          StdOutput ESI,Size=ECX,Eol=Yes
          LEA EDX,[ESI+ECX]    ; Stripped array is now at ESI..EDX.
          SUB EBX,EBX          ; EBX will keep the number of entered numbers.
          MOV EDI,Tab          ; Loaded numbers will be stored to Tab.
          DEC ESI
.50:      INC ESI
.60:      CMP ESI,EDX          ; 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 ESI
          LodD ESI
          JC .50:              ; Ignore numbers with wrong syntax.
          STOSD
          INC EBX
          JMP .60:
.80:      StdOutput ="Unsorted array of entered numbers:",Eol=Yes
          CALL .PrintTab:
          ShellSort Tab, EBX, 4, .Ascending:
          StdOutput ="Sorted ascending array of entered numbers:",Eol=Yes
          CALL .PrintTab:
          ShellSort Tab, EBX, 4, .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 EAX,[ESI]
             MOV EDX,[EDI]
             CMP EDX,EAX
             CLC
             JNL .Done:    ; Jump if both records are in order. No carry.
             MOV [ESI],EDX ; Otherwise swap them and return CF.
             MOV [EDI],EAX
             STC
.Done:       RET
            ENDP .Ascending:

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

.PrintTab:  PROC ; Display EBX numbers in Tab.
             MOV ECX,EBX
             MOV ESI,Tab
.Next:       LODSD
             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:

Bin:  DD 0           ; The first entered number in binary form.
Tab:  DD 128*DWORD   ; Table of entered numbers in binary form.
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 8*BYTE 0    ; The first number in hexdecimal notation.
      DB 0           ; Zero terminator.

     ENDPROGRAM tmac32

▲Back to the top▲