Page 1 of 1

Another NASM Question :)

Posted: Thu Jun 27, 2002 11:00 pm
by Brill
Hi, in nasm, i've declared a struct but when it comes to assembling time the error message about my scructs size "segment_descritor_size" not being defined before use. After reading the NASM manual it says i need to define a equ constant. I played around with it but i couldn't figure it out.
Can anyone please help?
I put:
segment_descriptor_size         EQU       $-segment_descriptor

segment_descriptor is the name of my struct. I put that in after declaring the struct, just like the nasm manual said.
Thanks.

Regards, Brill

RE:Another NASM Question :)

Posted: Thu Jun 27, 2002 11:00 pm
by carbonBased
Try this:

start_of_struct:
struc   mytype

  mt_long:      resd    1
  mt_word:      resw    1
  mt_byte:      resb    1
  mt_str:       resb    32

endstruc

type_size EQU $ - start_of_struct

I think that should work...

Jeff

RE:Another NASM Question :)

Posted: Thu Jun 27, 2002 11:00 pm
by carbonBased
Crap, never mind, nope, that wont work... because res? doesn't actually occupy any space, it's just a definition.

You can try it with an _instance_ of a structure, though:

mystruc:
    istruc mytype

        at mt_long, dd      123456
        at mt_word, dw      1024
        at mt_byte, db      'x'
        at mt_str,  db      'hello, world', 13, 10, 0

    iend

struct_length EQU $ - mystruc

I don't know if it'll work, but it's worth a try.

Jeff

RE:Another NASM Question :)

Posted: Thu Jun 27, 2002 11:00 pm
by Schol-R-LEA
Actually, res? declarations *do* REServe space (hence the name), they just don't initialize it.  

However (and I found this out while re-reading the NASM manual earlier today), struc *is* only a declaration is the structure to be reserved; you need to use istruc to actually set space aside and initialize it. SO my earlier advice was somewhat wrong.

RE:Another NASM Question :)

Posted: Thu Jun 27, 2002 11:00 pm
by carbonBased
Yeah, it reserves space, but doesn't it automatically put it in the .bss section?  In which case $ - start would by negative (as .bss is typically the last section).

In any event, yeah, that's more what I was getting at with the structure only being a definition and not reserving space.  Like I said, it should work fine with an actually instantiation of the struct.

Jeff

RE:Another NASM Question :)

Posted: Fri Jun 28, 2002 11:00 pm
by Brill
ok, i tried what you said, delcaring the size because it wasn't declared. Then it complained about redeclaring it :/. They way i've fixed it is to declare a new structure for every new segment descriptor that i wanted. which brings me to the conclusion that nasm structures aren't really structures. they are declaring space  for variables and then later, filling that space but after filling the space the structure can no long be used with new data (or at least without overwriting the old data that was put into the reserved space). Which means it isn't really a structure at all. Since structures are supposed to be a declaration of a structure of data so that the structure can then later be used as a "guide" to fill in further data later by many different instructions, using the structure. If you catch me ;). Which means i think structure support from nasm is shite ;).
But i do think nasm is still good though :).
If im wrong please tell me.

Regards, Brill