flat assembler
Message board for the users of flat assembler.

Index > Macroinstructions > macros to handle scape sequences

Author
Thread Post new topic Reply to topic
daluca



Joined: 05 Nov 2005
Posts: 86
daluca 04 Aug 2007, 07:04
hello: I have created these 2 macros to handle the scape sequence characters like
in the C languaje the names are str and stru for ascii and unicode they can be put
wherever the db or du can. (I think)

Code:

message: str 'Hello\nThere'

    


the colon after the message label is required,but the final 0 is not.
one good thing about these macros is that you can change the scape character
indicator :
I use the '\' as the scape indicator, and put only the n and t to be recognized as
scape sequences, but you can add any others you like

the only problem i have found is when you terminate the string with the character
indicator so if you want to print 'hello\' it would give an 'out of range' error
and this is because when the macro finds the '\' character it will load the next
character to see if it's one of the scape characters defined but there is nothimg more
to load, that is why the same scape indicator must be defined also as scape character
so the problem gets solved typing 'hello\\' and it will get printed correctly as
'hello\'

the behavior is different from the C compilers for instance: typing 'hello\q'
in borland C compiler will print 'helloq',so the '\' is ignored.
with these macros you will get 'hello\q' unless you have defined q to be other thing
lets say:
Code:

  else if char2 = 'q'
        char = '"'


    


then you will get :

Code:

'hello"'

    


here are the macros

Code:

macro str string
{          ;get strinf size
virtual at 0
db string
size=$-$$
end virtual
;-------------------------------
count = 1
repeat size
virtual at 1
db string


load char byte from count
if char = '\'
        load char2 byte from count+1
        if char2 = '\'
        char = '\'
        count = count+1
        else if char2 = 't'
        char = 9
        count =count+1
        else if char2 = 'n'
        char = 13
        count = count+1
        end if
end if
end virtual

db char
if count = size
        break
end if
count = count+1
end repeat
db 0
}


    




Code:

 macro stru string
{          ;get strinf size
virtual at 0
db string
size=$-$$
end virtual
;-------------------------------
count = 1
repeat size
virtual at 1
db string


load char byte from count
if char = '\'
        load char2 byte from count+1
        if char2 = '\'
        char = '\'
        count = count+1
        else if char2 = 't'
        char = 9
        count =count+1
        else if char2 = 'n'
        char = 13
        count = count+1
        end if
end if
end virtual

dw char
if count = size
        break
end if
count = count+1
end repeat
dw 0
}


    
Post 04 Aug 2007, 07:04
View user's profile Send private message Reply with quote
bogdanontanu



Joined: 07 Jan 2004
Posts: 403
Location: Sol. Earth. Europe. Romania. Bucuresti
bogdanontanu 04 Aug 2007, 07:42
Nice... but Very Happy

I find this much more clear, readable and more ASM style Wink
Code:
message  db 'Hello',13,10,'There',0
    


If needed you can always redefine:
Code:
ASCII_CR EQU 13
ASCII_LF EQU 10
    
Post 04 Aug 2007, 07:42
View user's profile Send private message Visit poster's website Reply with quote
Display posts from previous:
Post new topic Reply to topic

Jump to:  


< Last Thread | Next Thread >
Forum Rules:
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Copyright © 1999-2024, Tomasz Grysztar. Also on GitHub, YouTube.

Website powered by rwasa.