Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions
18
Task/String-length/Z80-Assembly/string-length.z80
Normal file
18
Task/String-length/Z80-Assembly/string-length.z80
Normal file
|
|
@ -0,0 +1,18 @@
|
|||
; input: HL - pointer to the 0th char of a string.
|
||||
; outputs length to B. HL will point to the last character in the string just before the terminator.
|
||||
; length is one-indexed and does not include the terminator. A null string will return 0 in B.
|
||||
|
||||
; "Terminator" is a label for a constant that can be configured in the source code. My code uses 0.
|
||||
; Sample Usage:
|
||||
; ld hl,MyString
|
||||
; call GetStringLength
|
||||
|
||||
GetStringLength:
|
||||
ld b,0
|
||||
loop_getStringLength:
|
||||
ld a,(hl) ;load the next char
|
||||
cp Terminator ;is it the terminator?
|
||||
ret z ;if so, exit.
|
||||
inc hl ;next char
|
||||
inc b ;increment the byte count
|
||||
jr loop_getStringLength
|
||||
Loading…
Add table
Add a link
Reference in a new issue