flat assembler
Message board for the users of flat assembler.
Index
> Main > struct members with predefined offsets? |
Author |
|
Tomasz Grysztar 10 Jan 2006, 15:26
For special purposes like this, the fasm's actual STRUC directive is better (because more flexible). With STRUC you've got many options how to do it, like:
Code: struc SomeStruct { .Var1 dd ? .Var2 dd ? dd 30 dup ? .Var3 dd ? } or Code: struc SomeStruct { . dd 33 dup ? label .Var1 at .+0 label .Var2 at .+4 label .Var3 at .+128 } |
|||
10 Jan 2006, 15:26 |
|
Big Red 10 Jan 2006, 16:26
Quote: struc SomeStruct That is very appealing indeed, but is there any way I can use struc to address register-based indexes in the fashion [ebx+SomeStruct.VarX] without having to define a actual structure in memory (as the struct definition does)? If there was a way to do this, I would "convert" to struc pretty quickly. Thank you very much EDIT: For example, if I define a struc structure as above like this (omitting the helper macros I would obviously have to implement to make it practical)... struc SomeStruct { . dd 33 dup ? label .Var1 at .+0 SomeStruc.Var1 equ 0 label .Var2 at .+4 SomeStruc.Var2 equ 4 label .Var3 at .+128 SomeStruc.Var3 equ 128 } ... then when I try to assemble an instruction such as mov eax,[ebx+SomeStruct.VarX], it will use the offset value from equ definition. Would this work, or would it cause compilation problems in some circumstances? Is there a better way? |
|||
10 Jan 2006, 16:26 |
|
Tomasz Grysztar 10 Jan 2006, 16:43
No, no, the STRUC needs to have an instance declared first, before you can use it. You can do it even this way:
Code: struc SomeStruct { .Var1 dd ? .Var2 dd ? dd 30 dup ? .Var3 dd ? } virtual at ebx SomeAtEbx SomeStruct ; define instance at EBX address end virtual and then: Code: mov eax,[SomeAtEbx.Var2] ; assembles to mov eax,[ebx+4] If you prefer to have the offsets only, you can do it like: Code: virtual at 0 SomeStruct SomeStruct ; define instance with the same name end virtual and then: Code: mov eax,[ebx+SomeStruct.Var2] (this is what "struct" macro does internally). Choose the one you like more. |
|||
10 Jan 2006, 16:43 |
|
Big Red 10 Jan 2006, 16:58
Quote: virtual at 0 Ah, thank you, that is exactly what I needed and needed to hear. Quote: No, no, the STRUC needs to have an instance declared first, before you can use it. You can do it even this way. ... sounds like you have to say that often. Maybe something to put in the documentation? ;) Thank you for the quick reply. Problem solved. |
|||
10 Jan 2006, 16:58 |
|
< Last Thread | Next Thread > |
Forum Rules:
|
Copyright © 1999-2024, Tomasz Grysztar. Also on GitHub, YouTube.
Website powered by rwasa.