flat assembler
Message board for the users of flat assembler.

Index > Macroinstructions > how to use macro in structure initialization?

Author
Thread Post new topic Reply to topic
zhak



Joined: 12 Apr 2005
Posts: 501
Location: Belarus
zhak 09 May 2013, 15:18
Hi guys.

Lets say I have a macro which pads fixed string with spaces:
Code:
macro padded_str len, text {
    local length
    length = $
    db text
    length = $-length
    db len-length dup (0x20)
}
    


and I have a structure, which holds this string:
Code:
struct my_struct
    string rb 32
ends
    


when I try to initialize the structure in source,
Code:
s my_struct padded_str 32, sz_some_text
    

it fails with 'invalid macro arguments' error

how to do it right? thanks
Post 09 May 2013, 15:18
View user's profile Send private message Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 20425
Location: In your JS exploiting you and your system
revolution 09 May 2013, 23:24
Macros and strucs are the same thing except for the label usage:
Code:
struc padded_str len, text {
    local length
    length = $
    db text
    length = $-length
    db len-length dup (0x20)
}

s padded_str 32, sz_some_text    
Post 09 May 2013, 23:24
View user's profile Send private message Visit poster's website Reply with quote
baldr



Joined: 19 Mar 2008
Posts: 1651
baldr 11 May 2013, 19:01
Because struc requires label to precede its invocation, it could be shortened to
Code:
struc padded_str len*, pad=' ', [text*] {
common
  . db text
    db .+len-$ dup pad
}

s padded_str 32,, sz_some_text    
sz_some_text looks somewhat strange, even if it is symbolic constant (I mean sz prefix, WRT 0x20 padding). Wink
Post 11 May 2013, 19:01
View user's profile Send private message Reply with quote
zhak



Joined: 12 Apr 2005
Posts: 501
Location: Belarus
zhak 12 May 2013, 00:41
I use this prefix (sz) to address null-terminated strings. like some sort of an acronym to String,Zero. But in this example, with padding, looks strange, I agree Smile
Post 12 May 2013, 00:41
View user's profile Send private message 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.