home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
C/C++ Interactive Guide
/
c-cplusplus-interactive-guide.iso
/
c_ref
/
csource3
/
104_01
/
stdlib.asm
< prev
next >
Wrap
Assembly Source File
|
1979-12-31
|
26KB
|
996 lines
title small c i/o package
extrn bios
bdos equ 5 ;address on entry address for bdos
cpmcmd equ 80h ;address of cpm command line
true equ 1 ;value for true
false equ 0 ;value for false
;
; toupper
;
; function: to shift lower case character to upper
;
; calling format from "c"
; toupper(char);
;
toupper:csect
mov a,l ;get character to test
cpi 61h ;check to see if less then 'a'
rc ;yes return to caller
cpi 7bh ;check to see if greater then 'z'
rnc ;yes..return to caller
ani 5fh ;mask off lowwer case bit
mov l,a ;put it in reg for return
ret ;return to caller
;
; tolowwer
;
; function: to convert character to lowwer case
;
; calling format from "c"
; tolowwer(char)
;
tolowwer:csect
mov a,l ;get character to shift to lowwer case
cpi 'A' ;see if less then 'A'
rc ;yes...return to caller
cpi 'Z'+1 ;see if greater then 'Z'
rnc ;yes...return to caller
ani 0bfh ;remove upper case bit
mov l,a ;put chracter back in place
ret
;
; isalpha
;
; function check to see if alpha character a-z or A-Z only
;
; calling format from "c"
; isalpha(char)
;
isalpha:csect
push h ;save calling arg for later
call isupper ;check to see if upper case
xchg ;put answer in de
pop h ;get character to test back
call islowwer ;check to see if lowwer case
dad d ;add isupper to is lowwer answer
ret
;
; isupper
;
; function: to check to see if character is upper case
;
; calling format in "c"
; isupper(char)
;
isupper:csect
mov a,l ;get character to check
cpi 'A' ;see if less then upper case a
jc isupper1 ;not upper case
cpi 'Z'+1 ;check to see if less then
jnc isupper1 ;no upper case
lxi h,true ;yes it is upper case
ret
isupper1:
lxi h,false ;not upper case
ret
;
; islowwer
;
; function: to check to see if character is lowwer case
;
; calling format from "c"
; islowwer(char)
;
islowwer:csect
mov a,l ;get character to check
cpi 'a' ;see if less then 'a'
jc islowwer1 ;yes...not upper case
cpi 'z'+1 ;is it greater then 'z'
jnc islowwer1 ;yes...not lower case
lxi h,true ;return true for lowwer case
ret
islowwer1:
lxi h,false ;return false for anything but lowwer case
ret
;
; isdigit
;
; function: to check to see if character is digit 0-9 only
;
; calling format from "c"
; isdigit(char)
;
isdigit:csect
mov a,l ;get character to test
cpi '0' ;see if less then a zero
jc isdigit1 ;yes...not a vaild digit
cpi '9'+1 ;is it greater than nine
jnc isdigit1 ;yes...not a vaild digit
lxi h,true ;is a vaild digit
ret
isdigit1:
lxi h,false ;not a vaild digit
ret
;
; isspace
;
; function: to check to see if white space tab or blank
;
; calling format from "c"
; isspace(char)
;
isspace:csect
mov a,l ;get character to check
lxi h,true ;assume true
cpi ' ' ;check for a space
rz
cpi 9 ;check for a tab
rz
lxi h,false
ret
;
; strlen
;
; function: to get the lenght of a string
;
; calling format in "c"
; len=strlen(string);
;
strlen: csect
xchg ;put address of string in de
lxi h,0 ;make string of zero lenght
strlen1:
ldax d ;get character from string
ora a ;check to see if end of string
rz ;yes return to caller
inx h ;add 1 to string lenght
inx d ;move to next character
jmp strlen1 ;loop till end of string found
;
; strcpy
;
; function: to copy first second string to first string
;
; calling format from "c"
; strcpy(object,source);
;
strcpy: csect
pop b ;get return address from stack
pop d ;get source address
pop h ;get object address
push h ;restore machine stack
push d
push b
push h
strcpy1:
ldax d ;get address of source character
mov m,a ;store character in object string
ora a ;check to see if end of string
jz strcpy2 ;end of string return to caller
inx h
inx d ;move pointer to next byte
jmp strcpy1 ;loop till done with copy
strcpy2:
pop h ;return address of object string
ret
;
; strcat
;
; function: to put string2 at then end of string1 and return address of
; string 1
;
; calling format in "c"
; strcat(string1,string2);
;
strcat: csect
pop b ;get return address
pop d ;get address of string 2
pop h ;get address of string 1
push h ;retore machine stack
push d
push b
push h ;save address of source string
strcat1:
mov a,m ;get character from source buffer
ora a ;check to see if zero
jz strcat2 ;yes end of string found
inx h ;move pointer to next byte
jmp strcat1 ;loop till end of string found
strcat2:
ldax d ;get character from string 2
mov m,a ;save character in string1
ora a ;check to see if end of buffer
jz strcat3 ;yes return to caller
inx h ;move object pointer up 1
inx d ;move source pointer up 1
jmp strcat2
strcat3:
pop h ;get address of string1
ret
; strpos
;
; function: to look for string 2 in string 1
;
; calling format in "c"
; strpos(string1,string2);
;
strpos: csect
call argload ;get args load into read be=1 de=2 hl=3
push b
pop h
lxi b,1 ;de=string2, hl=string1 bc=0
xchg
strpos1:
ldax d ;get character to check
ora a ;check to see if end of string
jz strpos5 ;end of string1 string 2 not found in string1
cmp m ;is it equal to string2 character 1
jz strpos2 ;yes...
inx d ;no add 1 to string 1 pointer
inx b ;add 1 to offset pointer
jmp strpos1 ;loop till end of string1 or string2 found
strpos2:
push h ;save strating address of string 21
push d ;save current address of string 1
strpos3:
inx d
inx h
mov a,m ;get character from string 2
ora a ;set machine flags
jz strpos4 ;end of string2 found must be a mathc
ldax d ;get arg1
cmp m ;is this character a match
jz strpos3
pop d ;restore pointer for string1 and string 2
pop h
inx d ;add 1 to string pointer
inx b ;add 1 to offset in string1
jmp strpos1 ;loop till end of string 1
strpos4:
mov l,c ;string found return offset for caller
mov h,b
pop b
pop b
ret
strpos5:
lxi h,0 ;string not found
ret
;
; setmem
;
; function: to fill a block of memory with a given constant
;
; calling format in "c"
; setmem(address,count,constant);
;
setmem: csect
pop b ;get return address
pop h ;get constant
mov a,l ;put constant in a
pop b ;get count
pop d ;get address
lxi h,8 ;offset in to put stack back
dad sp
sphl ;restore stack pointer
mov l,a ;place to save constant
setmem1:
mov a,b ;check to see if count is zero
ora c
rz ;all done with move
mov a,l ;get constant to store
stax d ;set memory loaction
inx d ;move pointer to next pointer
dcx b ;subtract 1 from count
jmp setmem1 ;loop till all bytes set
;
; movmem
;
; function: to move source address to object address for count bytes
;
; calling format from "C"
; movmem(source,object,count);
;
movmem: csect
call argload ;get args bc=1, de=2, hl=3
push b ;switch args so that
push d ;bc=count
push h ;de=object
pop b ;hl=source
pop h
pop d
mov a,b ;check to see if count = 0
ora c
rz ;zero return to caller
call movmemht ;check to see if source<dest
jc movmemt ;move tial first
mvi a,2 ;check to see if z80
inr a
jpe movmemf8 ;8080 do a byte by byte move
dw 0b0edh
ret
movmemf8:
mov a,m ;get source byte
stax d ;save byte in object buffer
inx h ;move object pointer up 1
inx d ;move source pointer up 1 byte
dcx b ;subtract 1 from count
mov a,b ;see if done
ora c
jnz movmemf8 ;no keep on looping
ret
movmemt:
dcx b ;tail first. compute new source
dad b ;and destination address
xchg
dad b
xchg
mvi a,2 ;check to see if z80
inr a
jpe movmemt8 ;8080 do a byte by byte move
dw 0b8edh
ret
movmemt8:
mov a,m ;get source byte
stax d ;save object byte
dcx h ;move to next byte of source buffer
dcx d ;move to next byte of object buffer
dcx b ;subtract 1 from count
mov a,b ;cehck to see if all done
ora c
jnz movmemt8 ;no keep on looping
ret
movmemht:
mov a,h
cmp d
rnz
mov a,l
cmp e
ret
;
; outp
;
; function: to output 1 byte t