UMBC CMSC 211 |
;; LENSTR.ASM--return length of C string pointed to on entry by si ;; ;; Calling Sequence: ;; EXTRN LenStr:NEAR ;; mov si, OFFSET theString ;; call LenStr ;; ;; On exit, ax contains the string's length (excluding the terminating ;; null byte) and si points to that byte. All other registers are ;; preserved. ;; ;; Program text from "Assembly Language for the IBM PC Family" by ;; William B. Jones, (c) Copyright 1992, 1997, Scott/Jones Inc. ;; .MODEL SMALL .CODE PUBLIC LenStr LenStr PROC mov ax, si ; save si to subtract at end LenLoop: cmp BYTE PTR [si], 0 je Done inc si jmp LenLoop Done: neg ax add ax, si ; ax := loc of null byte - loc of start ret LenStr ENDP END
;; CPYSTR.ASM--copy C string from si to di ;; ;; Calling Sequence: ;; EXTRN CpyStr:NEAR ;; mov si, OFFSET sourceString ;; mov di, OFFSET destinationString ;; call CpyStr ;; ;; On exit, si points to the null byte terminating the source string, ;; di to the null byte terminating the copied string, and all other ;; registers are preserved. ;; ;; Program text from "Assembly Language for the IBM PC Family" by ;; William B. Jones, (c) Copyright 1992, 1997, Scott/Jones Inc. ;; .MODEL SMALL .CODE PUBLIC CpyStr CpyStr PROC push ax ; We will use al for moving bytes CpyLoop: mov al, [si] mov [di], al cmp al, 0 ; Compare after move so null byte gets je Done ; moved, too inc si inc di jmp CpyLoop Done: pop ax ret CpyStr ENDP END
;; CMPSTR.ASM--return ax < 0, = 0, > 0 according as string at si is ;; <, =, or > string at di ;; ;; Calling Sequence: ;; EXTRN CmpStr:NEAR ;; mov si, OFFSET leftString ;; mov di, OFFSET rightString ;; call CmpStr ;; ;; On exit, ax contains the result and all other registers are ;; preserved ;; ;; Program text from "Assembly Language for the IBM PC Family" by ;; William B. Jones, (c) Copyright 1992, 1997, Scott/Jones Inc. ;; .MODEL SMALL .CODE PUBLIC CmpStr CmpStr PROC push si push di CharLoop: mov al, [si] mov ah, [di] cmp al, ah ; Must compare bytes before checking for jne Done ; termination cmp al, 0 ; Now check for either string terminated je Done cmp ah, 0 je Done ; Anything ending loop treated the same inc si inc di jmp CharLoop Done: sub al, ah cbw ; Extend result to full word pop di pop si ret CmpStr ENDP END