RosettaCodeData/Task/String-case/8080-Assembly/string-case.8080

38 lines
981 B
Plaintext

org 100h
jmp demo
;;; Convert CP/M string under [HL] to upper case
unext: inx h
ucase: mov a,m ; Get character <- entry point is here
cpi '$' ; Done?
rz ; If so, stop
cpi 'a' ; >= 'a'?
jc unext ; If not, next character
cpi 'z'+1 ; <= 'z'?
jnc unext ; If not, next character
sui 32 ; Subtract 32
mov m,a ; Write character back
jmp unext
;;; Convert CP/M string under [HL] to lower case
lnext: inx h
lcase: mov a,m ; Get character <- entry point is here
cpi '$' ; Done?
rz ; If so, stop
cpi 'A' ; >= 'A'?
jc lnext ; If not, next character
cpi 'Z'+1 ; <= 'Z'?
jnc lnext ; If not, next character
adi 32 ; Subtract 32
mov m,a ; Write character back
jmp lnext
;;; Apply to given string
demo: call print ; Print without change
lxi h,str
call ucase ; Make uppercase
call print ; Print uppercase version
lxi h,str
call lcase ; Make lowercase (fall through to print)
print: lxi d,str ; Print string using CP/M call
mvi c,9
jmp 5
str: db 'alphaBETA',13,10,'$'