RosettaCodeData/Task/Empty-string/Z80-Assembly/empty-string-2.z80

18 lines
435 B
Z80 Assembly

ld hl,MyString
GetStringLength:
ld b,0 ;zero the length counter
loop_getStringLength:
ld a,(hl)
or a ;compare A to zero
ret z ;exit if zero
inc hl ;next char
inc b ;add 1 to length counter
jr loop_getStringLength
ld a,b ;load B into A
or a ;compare A to zero (effectively comparing B to zero)
jr z,StringIsEmpty
;your code for what happens when MyString is not empty goes here.