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$ %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$
SIZE# %Destination
.
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$ %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