flat assembler
Message board for the users of flat assembler.
Index
> Macroinstructions > Search for string, instructions, etc |
Author |
|
Borsuc 19 Jan 2010, 19:59
use
Code: loc = $$+%-1 The best way to understand this is that the preprocessor deals with symbolic, or "text" constants... and the assembly stage (i.e the '=') deals with NUMERIC constants (numbers). and 'repeat' is assembly stage, so you have to use '=' also there is a faster way, if you load a 'word' instead of 'byte' (i.e 2 bytes), but for arbitrary strings it's gonna be pretty slow if you make it work for ANY string. Here's one way to do it for any string (using a macro) that returns the string position into 'StringPos' assembly-time variable: Code: macro GetStringPos [String] { common local s, p, n, a, b virtual at 0 db String s = $ ; gets the length of the string into 's' end virtual p = $$ n = 1 while $-p >= s & n=1 n = 0 repeat s load a byte from p+%-1 virtual at p db String load b byte from p+%-1 end virtual if a <> b if % > 1 p = p-1 end if p = p+% n = 1 break end if end repeat end while if n = 0 StringPos = p else err 'String was not found' end if } db '1234Som__SomeString_test' GetStringPos 'Some' db StringPos _________________ Previously known as The_Grey_Beast |
|||
19 Jan 2010, 19:59 |
|
revolution 20 Jan 2010, 02:12
score_under wrote:
Code: repeat $-$$-1 ... load b byte from $$+% |
|||
20 Jan 2010, 02:12 |
|
< Last Thread | Next Thread > |
Forum Rules:
|
Copyright © 1999-2024, Tomasz Grysztar. Also on GitHub, YouTube.
Website powered by rwasa.