flat assembler
Message board for the users of flat assembler.
![]() |
Author |
|
revolution 20 Apr 2009, 10:45
See the manual, it may help you.2.3.4 Structures
|
|||
![]() |
|
pete 20 Apr 2009, 11:25
I know how to define structures in the data section, but i want to define them in allocated memory!
To describe my problem more precisely: about 10*50 Byte buffers are needed, IF a certain case occures (i.e.: user presses button); for this case it's probably cleaner to Heap-allocate some memory instead of using the stack, right? So what i want to do is to allocate ONCE all 500 Bytes, and then "split" the allocated memory into 10 buffers that i can access with names. I've read the chapter 2.3.4. but haven't found an answer. |
|||
![]() |
|
revolution 20 Apr 2009, 11:30
Code: struc struct1 { .member1 dd ? } virtual at 0 struct1 struct1 end virtual ... mov eax,[ebx+struct1.member1] Last edited by revolution on 20 Apr 2009, 15:56; edited 1 time in total |
|||
![]() |
|
pete 20 Apr 2009, 11:47
Aren't the first three lines supposed to be inside the data section? If yes, then i would allocate the needed memory twice?
Why "virtual at 0"? Sorry, i don't get it.... Could you please explain if time permits? |
|||
![]() |
|
revolution 20 Apr 2009, 11:56
The first three lines can be anywhere above the first use of the struct1 structure.
If you want your structure zero-based then "at 0" is what you put. If you want it eax-based the "at eax" is what you put. Code: virtual at esi struct1 struct1 end virtual ... mov eax,[struct1.member1] ;same as: mov eax,[esi+0] Last edited by revolution on 20 Apr 2009, 13:40; edited 1 time in total |
|||
![]() |
|
pete 20 Apr 2009, 12:17
Great, thank you!!!
This is what i added after the allocation: Code: virtual at eax tbuf1 rb 50 tbuf2 rb 50 ... end virtual test: mov word[tbuf1],0x0025 mov word[tbuf2],0x0025 |
|||
![]() |
|
pete 20 Apr 2009, 12:34
But is something equivalent possible by using the EQU directive? Right now, i have to set eax correctly each time i want to access buffers inside my virtual space.
The address of the first byte of the space is stored at aheap. "virtual at [aheap]" doesnt work... |
|||
![]() |
|
revolution 20 Apr 2009, 13:39
The assembler cannot do magic for you. You will have to load at least one register first before you can access the memory pointed by the aheap variable. The limitation is you would need to do two lookups in one instruction.
Code: mov [[aheap]+offset],someValue |
|||
![]() |
|
pete 20 Apr 2009, 13:55
Thanks revolution, i see now. Since eax is dynamic it's impossible to "fix" it's value when compiling the application.
|
|||
![]() |
|
LocoDelAssembly 20 Apr 2009, 15:48
In case it wasn't clear, in the first revolution's suggestion of "virtual at 0" you would normally do something like this:
Code: struct Point { .x dd ? .y dd ? } virtual at 0 Point Point end virtual . . . ; EBX = Holds a pointer to the structure mov eax, [ebx+Point.y] ; mov eax, [ebx+4] |
|||
![]() |
|
revolution 20 Apr 2009, 15:57
LocoDelAssembly: Yes, thanks. Just to avoid confusion I have corrected the offending code above.
|
|||
![]() |
|
f0dder 20 Apr 2009, 16:26
Quote:
Those are incorrect - heap exceptions are exceptions, they don't give you return values. Check out SEH (Structured Exception Handling) ![]() |
|||
![]() |
|
pete 21 Apr 2009, 06:55
Since i do a lot of scripting, i wasn't aware that eax couldn't get fixed at compilation time... But instead of virtual i'm now using simple equ, since i can't figure out an positive aspect to use virtual over equ; here's the part of my program:
Code: tbuf1 equ eax tbuf2 equ eax+0x32 mov word[tbuf1],0x0025 mov word[tbuf2],0x0025 Works exactly for me as when using virtual. Thanks for pointing that out (SEH), f0dder! |
|||
![]() |
|
f0dder 21 Apr 2009, 08:15
Quote: But instead of virtual i'm now using simple equ, since i can't figure out an positive aspect to use virtual over equ ![]() |
|||
![]() |
|
pete 21 Apr 2009, 08:39
I havn't had troubles with equ yet.
|
|||
![]() |
|
< Last Thread | Next Thread > |
Forum Rules:
|
Copyright © 1999-2025, Tomasz Grysztar. Also on GitHub, YouTube.
Website powered by rwasa.