home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Power-Programmierung
/
CD1.mdf
/
assemblr
/
library
/
psp_io
/
charstr.asm
next >
Wrap
Assembly Source File
|
1994-05-28
|
5KB
|
120 lines
;****************************************************************************
; C H A R S T R . A S M
;============================================================================
; Functions to manipulate ascii chars and strings.
;---------------------------------------------------------------------------
; Copyright (c) Simon Groes, 1994
;---------------------------------------------------------------------------
; Assemble with Borland Turbo Assembler v3.0
;****************************************************************************
IDEAL
DOSSEG
MODEL small
LOCALS
;----- Insert INCLUDE "filename" directives here
INCLUDE "macro.inc"
INCLUDE "common.inc"
;----- Insert EQU and = equates here
DATASEG
;----- Declare other variables with DB, DW, etc., here
;----- Specify any EXTRN variables here
CODESEG
;----- Declare PUBLIC procedures here
PUBLIC charToUpper
PUBLIC strLength, strCopy
;===============================================================
; Procedure: =*=strLength=*=
;---------------------------------------------------------------
; Usage: Public - May be used in this & other asm files.
; Task: Return length of string.
; Input: di = Offset address of string.
; Output: Length of string in cx.
; Registers: cx changed
;===============================================================
PROC strLength
SaveRegs <es,di,ax> ; Save modified register(s).
smove es, ds ; es = data segment.
mov al, NULL ; End of string marker.
mov cx, 0FFFFh ; cl <- maximum value (FFFFh = -1).
cld ; Auto increment di
or cx, cx ; Reset zero flag
repnz scasb ; cmp di with al, inc di, dec cl
neg cx ; cx = 1 + stringLength + NULL
dec cx ; cx = stringLength + NULL
dec cx ; cx = stringLength
RestoreRegs <ax,di,es> ; Restore modified register(s).
ret ; Return to caller
ENDP strLength
;===============================================================
; Procedure: =*=charToUpper=*=
;---------------------------------------------------------------
; Usage: Public - may be used by other asm files.
; Task: Convert lowercase char to uppercase.
; Input: al = character.
; Output: al = character in uppercase.
; Registers: ax may be changed.
;===============================================================
PROC charToUpper
cmp al, 'a' ; Is char a lowercase letter?
jb @@Return
cmp al, 'z'
ja @@Return ; NO -> End routine.
sub al, 'a'-'A' ; YES-> Convert to uppercase.
@@Return:
ret ; Return to caller.
ENDP charToUpper
;===============================================================
; Procedure: =*=strCopy=*=
;---------------------------------------------------------------
; Usage: Public - may be used by other files.
; Task: Copy string from one memory location to another.
; Input: si = Address of source string (s1).
; di = Address of destination (s2).
; Output: String copied to new location.
; Registers: none
; Note: s2 must be large enough to hold s1+NULL.
;===============================================================
PROC strCopy
SaveRegs <es,si,di,cx>
smove es, ds ; es = data segment.
xchg si, di ; di = s1; Save di in si.
call strLength ; cx = length of s1.
xchg si, di ; Restore si & di.
cmp si, di ; Is si at a lower address than di?
jb @@Reverse ; Yes: Start copying at end of string.
cld ; No: Auto increment,
jmp NEAR @@Copy ; and goto copy routine.
@@Reverse:
add si, cx ; Move si to end of string. si -> NULL.
add di, cx ; Move di to end of string buffer.
std ; Auto-decrement.
@@Copy:
inc cx ; cx = stringlength + 1.
repnz movsb ; Copy string to new location.
RestoreRegs <cx,di,si,es>
ret
ENDP strCopy
END ; End of module.