EuroAssembler Index Manual Download Source Macros


Sitemap Links Forum Tests Projects

string16.htm
Macros
Concat$
Compare$
GetLength$

This file can be included to 16bit programs written in Euro Assembler.
It contains OS-independent macros for zero-terminated (ASCIIZ) string operations.

All functions expect direction flag on input be zero and they do not change it.

Similar macros with identical names for different program width are defined in string32.htm and string64.htm.


 string16 HEAD
↑ GetLength$ String
This macro returns the size of ASCIIZ string in bytes. The terminating NUL character is not counted.
Input
String is pointer to a zero terminated string of ANSI characters. It may also be a literal string.
ES= segment of the String.
Output
CX= size of the string in bytes without the terminating NUL.
GetLength$ %MACRO String
     %IF "%String" !== "CX"
       MOV CX,%String
     %ENDIF
     CALL GetLength$@RT::
       GetLength$@RT:: PROC1
          PUSH AX,DI
            MOV DI,CX
            XOR AX,AX
            XOR CX,CX
            CLD
            DEC CX
            REPNE SCASB
            NOT CX
            DEC CX
         POP DI,AX
         RET
       ENDPROC1 GetLength$@RT::
   %ENDMACRO GetLength$
↑ Concat$ Destination, Size=, Source1, Source2,,,
Macro will concatenate one or more zero-terminated source strings to a destination string.
All source strings must be addressable with DS. Destination must be addressable with ES.
Input
Destination is a pointer to an output buffer where the result of concatenation will be stored as zero-terminated byte string.
ES= is segment of Destination string.
Size= is the size allocated for the output destination buffer including the zero terminator. By default it is set to SIZE# %Destination.
Source* operands are pointers to the ASCIIZ strings which are being concatenated. The first one (Source1) may be identical with the destination, when we need to append something to an existing string.
DS= is segment of all Source strings.
Output
CF=0, Destination string is filled with concatenation of all Source strings. Registers are preserved.
CF=1 when the allocated Size= is not long enough. The output buffer Size is never exceeded.
Example
Concat$ FullName$,Path$,FileName$,=B".htm"
Concat$ %MACRO Destination, Source,,, Size=
   %IF %# < 2                                                                      ; >
     %ERROR ID=5930, 'Missing operand of macro "Concat$".'
     %EXITMACRO Concat$
   %ENDIF
   PUSH BP
     MOV BP,SP ; Store stack pointer.
     ArgNr %FOR %#..2, STEP= -1
       PUSHW %*{%ArgNr} ; All Source pointers, starting with the last.
     %ENDFOR ArgNr
     PUSHW %# - 1  ; Number of Source strings to concatenate.
     %IF "%Size" === ""
       PUSHW SIZE# %Destination
     %ELSE
        PUSHW %Size
     %ENDIF
     PUSHW %Destination
     CALL Concat$@RT::
     MOV SP,BP ; Restore stack.
   POP BP
Concat$@RT:: PROC1
     PUSHAW
       MOV BP,SP
       MOV DI,[BP+18] ; %Destination.
       MOV DX,[BP+20] ; %Size.
       MOV CX,[BP+22] ; Number of source strings.
       ADD DX,DI
       CLD
       DEC DX ; End of allocated Destination.
 .20:  MOV SI,[BP+24] ; Source pointer.
 .30:  LODSB
       CMP AL,0
       JE .40:
       CMP DI,DX
       CMC
       JC .80: ; If destination size overflowed.
       STOSB
       JMP .30:
 .40:  INC BP,BP ; The next Source pointer.
       LOOP .20:
 .80:  MOV AL,0
       STOSB
     POPAW
     RET
   ENDP1 Concat$@RT::
 %ENDMACRO Concat$
↑ Compare$ String1, String2
Compare two zero-terminated strings.
Input
String1 is pointer to the first zero-terminated string. SI is assumed when the first operand is omitted.
DS= is segment of the first string.
String2 is pointer to the second zero-terminated string. DI is assumed when the first operand is omitted.
ES= is segment of the second string.
Output
ZF=1 if both string are identical,
ZF=0 otherwise.
Compare$ %MACRO String1, String2
   %IF "%String2" === ""
     PUSHW DI
   %ELSE
     PUSHW %String2
   %ENDIF
   %IF "%String1" === ""
     PUSHW SI
   %ELSE
     PUSHW %String1
   %ENDIF
   CALL Compare$@RT::
Compare$@RT:: PROC1
       PUSHAW
         MOV BP,SP
         SUB AX,AX
         MOV DI,[BP+20] ; %String2.
         MOV CX,-1
         MOV BX,DI
         CLD
         REPNE:SCASB    ; Search for the terminator of string ES:DI.
         SUB DI,BX      ; Size of String2 including the NUL.
         MOV DX,DI
         MOV DI,[BP+18] ; %String1$.
         MOV CX,-1
         MOV SI,DI
         PUSH ES,DS
          POP ES        ; Temporarily load ES from DS.
          REPNE:SCASB   ; Search for the terminator of string DS:SI.
         POP ES
         MOV CX,DI
         SUB CX,SI      ; Size of %String1 including the NUL.
         CMP CX,DX      ; Compare string sizes.
         JNE .90        ; If sizes do not match.
         MOV DI,BX      ; String1$.
         REPE CMPSB
   .90:POPAW
       RET 2*2
      ENDPROC1 Compare$@RT::
  %ENDMACRO Compare$
  ENDHEAD string16

▲Back to the top▲