Omnimaga
Calculator Community => TI Calculators => ASM => Topic started by: TiAddict on July 02, 2011, 08:16:47 pm
-
So, i want to use "inString(" command and "sub(" in ASM, and i need someone to show me the routine. I dont know why, but the one on the "Learn ASM in 28 days" isnt working. Is there other way, using the null string?
HL=address of string to look for
DE=address of string to find
A=positon
-
Is A input, output, or both?
-
I think this is around what you want:
;############################
;input: hl = start of string
; de = string to find
;output: hl = start of string in string
; b = offset to start of string
; carry if string not found
inString:
ld b, 0
inStringLp:
ld a, (hl)
or a
scf
ret z
ld a, (de)
cp (hl)
jr nz, notAMatch
push hl
push de
checkMatchLoop:
inc hl
inc de
ld a, (de)
or a
jr nz, notTotalMatch
pop de
pop hl
ret
notTotalMatch:
cp (hl)
jr z, checkMatchLoop
pop de
pop hl
notAMatch:
inc b
inc hl
jr inStringLp
I could make it faster, but it would be bigger, so it's a trade.
Edit:
After reading that section of 28 days, I should mention that you need to use zero terminated strings for this. You will almost never use length prefixed, so don't worry about that.
-
Thanks!!! :D yeah i know.. 28 days have the length prefixed, and mimas doesnt support it.
-
It's not hard to do in Mimas, just do this:
.db 5
.db "Hello"
-
thepenguin77: would it work any better to use CPI/CPIR? Just a question.
-
I noticed a while ago that the routine supplied in 28 days doesn't account for partial matches. There are also a few other errors in some routines...
-
thepenguin77: would it work any better to use CPI/CPIR? Just a question.
I could make it faster, but it would be bigger, so it's a trade.
Yep. Faster, but bigger. You could make it yourself, it would give you valuable experience with cpi, which is used once like every 10 programs.