flat assembler
Message board for the users of flat assembler.

Index > Macroinstructions > Macro to simulate headers in structs

Author
Thread Post new topic Reply to topic
beppe85



Joined: 23 Oct 2004
Posts: 181
beppe85
Hi. . .

I wanted a way to define a kind of headers in structs, which will be at the left of the pointer. To put it simple, some fields will have negative offsets.

As I was not aware of a solution already, I extended the default struct to do so:

Code:
; structure definition helper

macro struct name
{
    name@struct fix name
    normal@struct = 0
    struc name {
}

macro struct_helper name
{
    local ..name
    virtual at 0
    ..name name
    end virtual

    normal.#name = normal@struct

    virtual at -normal@struct
    name name
    sizeof.#name = $ - name
    name equ sizeof.#name
    end virtual
}

ends fix } struct_helper name@struct

macro normal
{
    normal@struct = $
}    


Example of use:
Code:
struct MemoryBlock
    .sig        dd ?
    .size       dd ?
    .next       dd ?
normal
    .data       rb 0
ends

display '-', -MemoryBlock.size + '0'    


If you forget "normal", you'll get the good and old struct. If you repeat more times, just the last is valid.

Hope it will be useful to someone else. Smile

[]'s

Beppe

UPDATE: fixed normal when ommited.

_________________
"I assemble, therefore I am"

If you got some spare time, visit my blog: http://www.beppe.theblog.com.br/ and sign my guestmap


Last edited by beppe85 on 03 Jun 2005, 03:24; edited 2 times in total
Post 29 May 2005, 21:47
View user's profile Send private message Reply with quote
vid
Verbosity in development


Joined: 05 Sep 2003
Posts: 7105
Location: Slovakia
vid
nice, could be in standard package. I usually use such things once-twice per project
Post 29 May 2005, 21:59
View user's profile Send private message Visit poster's website AIM Address MSN Messenger ICQ Number Reply with quote
beppe85



Joined: 23 Oct 2004
Posts: 181
beppe85
The programmer just must be made aware that when he/she declares a variable of a struct using normal, that will point to the very first field, not to the field after normal. I'm using this together with pointers, so I'll had to do the sliding anyway. Also, It does makes sense to have the following command inside and at the end of struct_helper:

normal.#name = normal@struct
Post 30 May 2005, 20:45
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-2020, Tomasz Grysztar.

Powered by rwasa.