Author Topic: help me with the string commands  (Read 3294 times)

0 Members and 1 Guest are viewing this topic.

Offline TiAddict

  • LV3 Member (Next: 100)
  • ***
  • Posts: 68
  • Rating: +0/-0
    • View Profile
help me with the string commands
« 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
« Last Edit: July 02, 2011, 08:22:23 pm by TiAddict »

Offline calcdude84se

  • Needs Motivation
  • LV11 Super Veteran (Next: 3000)
  • ***********
  • Posts: 2272
  • Rating: +78/-13
  • Wondering where their free time went...
    • View Profile
Re: help me with the string commands
« Reply #1 on: July 03, 2011, 12:07:11 am »
Is A input, output, or both?
"People think computers will keep them from making mistakes. They're wrong. With computers you make mistakes faster."
-Adam Osborne
Spoiler For "PartesOS links":
I'll put it online when it does something.

Offline thepenguin77

  • z80 Assembly Master
  • LV10 31337 u53r (Next: 2000)
  • **********
  • Posts: 1594
  • Rating: +823/-5
  • The game in my avatar is bit.ly/p0zPWu
    • View Profile
Re: help me with the string commands
« Reply #2 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.
« Last Edit: July 03, 2011, 12:56:00 am by thepenguin77 »
zStart v1.3.013 9-20-2013 
All of my utilities
TI-Connect Help
You can build a statue out of either 1'x1' blocks or 12'x12' blocks. The 1'x1' blocks will take a lot longer, but the final product is worth it.
       -Runer112

Offline TiAddict

  • LV3 Member (Next: 100)
  • ***
  • Posts: 68
  • Rating: +0/-0
    • View Profile
Re: help me with the string commands
« Reply #3 on: July 03, 2011, 01:13:28 am »
Thanks!!! :D yeah i know.. 28 days have the length prefixed, and mimas doesnt support it.

Offline thepenguin77

  • z80 Assembly Master
  • LV10 31337 u53r (Next: 2000)
  • **********
  • Posts: 1594
  • Rating: +823/-5
  • The game in my avatar is bit.ly/p0zPWu
    • View Profile
Re: help me with the string commands
« Reply #4 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"
zStart v1.3.013 9-20-2013 
All of my utilities
TI-Connect Help
You can build a statue out of either 1'x1' blocks or 12'x12' blocks. The 1'x1' blocks will take a lot longer, but the final product is worth it.
       -Runer112

Offline calcdude84se

  • Needs Motivation
  • LV11 Super Veteran (Next: 3000)
  • ***********
  • Posts: 2272
  • Rating: +78/-13
  • Wondering where their free time went...
    • View Profile
Re: help me with the string commands
« Reply #5 on: July 03, 2011, 01:36:02 am »
thepenguin77: would it work any better to use CPI/CPIR? Just a question.
"People think computers will keep them from making mistakes. They're wrong. With computers you make mistakes faster."
-Adam Osborne
Spoiler For "PartesOS links":
I'll put it online when it does something.

Offline ZippyDee

  • LV8 Addict (Next: 1000)
  • ********
  • Posts: 729
  • Rating: +83/-8
  • Why not zoidberg?
    • View Profile
Re: help me with the string commands
« Reply #6 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...
There's something about Tuesday...


Pushpins 'n' stuff...


Offline thepenguin77

  • z80 Assembly Master
  • LV10 31337 u53r (Next: 2000)
  • **********
  • Posts: 1594
  • Rating: +823/-5
  • The game in my avatar is bit.ly/p0zPWu
    • View Profile
Re: help me with the string commands
« Reply #7 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.
zStart v1.3.013 9-20-2013 
All of my utilities
TI-Connect Help
You can build a statue out of either 1'x1' blocks or 12'x12' blocks. The 1'x1' blocks will take a lot longer, but the final product is worth it.
       -Runer112