Omnimaga

Calculator Community => TI Calculators => ASM => Topic started by: TiAddict on July 02, 2011, 08:16:47 pm

Title: help me with the string commands
Post 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
Title: Re: help me with the string commands
Post by: calcdude84se on July 03, 2011, 12:07:11 am
Is A input, output, or both?
Title: Re: help me with the string commands
Post by: thepenguin77 on July 03, 2011, 12:51:46 am
I think this is around what you want:

Code: [Select]
;############################
;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.
Title: Re: help me with the string commands
Post by: TiAddict on July 03, 2011, 01:13:28 am
Thanks!!! :D yeah i know.. 28 days have the length prefixed, and mimas doesnt support it.
Title: Re: help me with the string commands
Post by: thepenguin77 on July 03, 2011, 01:18:51 am
It's not hard to do in Mimas, just do this:
Code: [Select]
.db 5
.db "Hello"
Title: Re: help me with the string commands
Post by: calcdude84se on July 03, 2011, 01:36:02 am
thepenguin77: would it work any better to use CPI/CPIR? Just a question.
Title: Re: help me with the string commands
Post by: ZippyDee on July 03, 2011, 01:52:51 am
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...
Title: Re: help me with the string commands
Post by: thepenguin77 on July 04, 2011, 05:11:23 pm
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.