EuroAssembler Index Manual Download Source Macros


Sitemap Links Forum Tests Projects

tmac16.htm

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

Format
MZ 16bit
Platform
DOS
Build
euroasm tmac16.htm
Run
tmac16
See also
tmac32.htm, tmac64.htm.
       EUROASM UNICODE=Off
tmac16 PROGRAM Format=MZ,Width=16,IconFile=,Entry=Main:
        INCLUDE dosapi.htm, cpuext%^WIDTH.htm, sort%^WIDTH.htm
Main:   PROC
          MOV AX,PARA# [DATA]
          MOV DS,AX
          MOV ES,AX
          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 -32768..+32767, for instance",Eol=Yes
          StdOutput =" 12345, -12,0,-32768, +32767, 54321",Eol=Yes
          StdOutput ="-------------------------------------------------",Eol=Yes
          StdInput  Raw
          MOV DI,Raw
          MOV SI,DI
          MOV CX,SIZE# Inp
          MOV AL,','
          REPNE SCASB
          JNE .10:
          DEC DI
.10:      DEC DI
          CMP DI,SI
          JNA .20:
          CMPB [DI],' '
          JBE .10:
.20:      SUB DI,SI
          MOV CX,DI
          INC CX
          MOV DI,Inp
          REP MOVSB
          StdOutput ="The first entered number:",Eol=Yes
          StdOutput Inp, Size=DI,Eol=Yes
          StdOutput ="Conversion from decimal to binary and back with macros LodD and StoD:",Eol=Yes
          LodD Inp
          JC .Abort:
          MOV [Bin],AX
          StoD Dec
          JC .Abort:
          StdOutput Dec,Eol=Yes
          StdOutput ="Conversion from binary to hexadecimal with macro StoH Align=Left:",Eol=Yes
          MOV AX,[Bin]
          StoH Hex,Align=Left
          JC .Abort:
          StdOutput ="0x",Hex,Eol=Yes
          StdOutput ="Conversion from binary to hexadecimal with macro StoH Align=Right,Size=4:",Eol=Yes
          MOV AX,[Bin]
          StoH Hex,Align=Right
          JC .Abort:
          StdOutput ="0x",Hex,Eol=Yes
          MOV SI,Raw
          MOV DI,Raw + SIZE# Raw
.30:      DEC DI
          CMP DI,SI
          JNA .40:
          CMPB [DI],' '
          JBE .30:
.40:      SUB DI,SI
          INC DI             ; Netto size of the stripped list.
          StdOutput ="Entered array of numbers:",Eol=Yes
          StdOutput SI,Size=DI,Eol=Yes
          MOV DX,DI          ; Netto size of the stripped list.
          ADD DX,SI          ; SI..DX is the list of decimal numbers.
          SUB BX,BX          ; BX will keep the number of entered numbers.
          MOV DI,Tab         ; Loaded numbers will be stored to Tab.
          DEC SI
.50:      INC SI
.60:      CMP SI,DX          ; 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 SI
          LodD SI
          JC .50:            ; Ignore incorrect numbers.
          STOSW
          INC BX
          JMP .60:
.80:      StdOutput ="Unsorted array of entered numbers:",Eol=Yes
          CALL .PrintTab:
          ShellSort Tab, BX, 2, .Ascending:
          StdOutput ="Sorted ascending array of entered numbers:",Eol=Yes
          CALL .PrintTab:
          ShellSort Tab, BX, 2, .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 SI,DI.
             MOV AX,[SI]
             MOV DX,[DI]
             CMP DX,AX
             CLC
             JNL .Done:    ; Jump if both records are in order. No carry.
             MOV [SI],DX   ; Otherwise swap them and return CF.
             MOV [DI],AX
             STC
.Done:       RET
            ENDP .Ascending:

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

.PrintTab:  PROC ; Display EBX numbers in Tab.
             MOV CX,BX
             MOV SI,Tab
.Next:       LODSW
             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:  DW 0           ; The first entered number in binary form.
Tab:  DD 128* WORD   ; 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 4*BYTE 0    ; The first number in hexdecimal notation.
      DB 0           ; Zero terminator.
     ENDPROGRAM tmac16

▲Back to the top▲