String matching: Difference between revisions

Content added Content deleted
m (→‎{{header|MIPS Assembly}}: formatting fix)
Line 4,903: Line 4,903:
</pre>
</pre>



=={{header|Z80 Assembly}}==
{{trans|MIPS Assembly}}
<lang z80>InString:
;input: hl = pointer to string 1
; de = pointer to string 2
; assumes len(hl) <= len(de)
; output in BC
;clobbers: ix
push de
pop ix ;back up de into ix
ld bc,0 ;our return value
InString_again:
ld a,(hl)
or a
ret z
ld a,(de)
or a
ret z
cp (hl)
jr nz,InString_noMatch
inc de
jr InString_overhead
InString_noMatch:
push ix
pop de
inc bc
InString_overhead:
inc hl
jr InString_again</lang>

{{out}}
<lang z80>org &1000
ld hl,TestString
ld de,Test1 ;recompiled with each test string and tested it
call InString
ld a,c
call ShowHex
ret

TestString:
db "abcdefg",0
Test1:
db "abc",0 ;returns 0
Test2:
db "def",0 ;returns 3
Test3:
db "efg",0 ;returns 4
Test4:
db "z",0 ;returns 7</lang>


=={{header|zkl}}==
=={{header|zkl}}==