flat assembler
Message board for the users of flat assembler.
 Home   FAQ   Search   Register 
 Profile   Log in to check your private messages   Log in 
flat assembler > Main > Local struc on stack

Author
Thread Post new topic Reply to topic
donn



Joined: 05 Mar 2010
Posts: 67
Local struc on stack
Hi, is there an equivalent to:


Code:

label .localValue dword at ebp-4




for strucs? I tried some variations but will keep trying. Instead of placing a new struc on the heap, was aiming to place a disposable one on the stack. With each call to the same function, it could then use the same struc layout, but on its own stack. This sounds preferable to using a single global struc address.

Was referencing vid's post here: http://board.flatassembler.net/topic.php?t=12066&postdays=0&postorder=asc&start=20

Thanks a bunch.
Post 10 Aug 2016, 15:34
View user's profile Send private message Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 15301
Location: Bigweld Industries
The short answer is, yes. But it depends upon what you are doing. Are you using the Windows "struct" macros? Or something else. Post some code snippets of your function definitions to give us something to work with.
Post 10 Aug 2016, 15:38
View user's profile Send private message Visit poster's website Reply with quote
donn



Joined: 05 Mar 2010
Posts: 67
Unfortunately, I do not have an up to date version of the function I was working on here. It was something like this:


Code:

        struc ListItem{
                .item dd 0
                .previous dd 0
                .next dd 0
                .itemSize dd 0
                .endListItemAddress dd 0
        }

        ; Used with address offsets
        virtual at 0
                ListItem ListItem
        end virtual






Code:
;------------
;   Inserts item at the current position index.
;   Updates list item count, item previous and next addresses, etc.
;   Takes List address, item address as parameters
;------------
newNextItem:
        push ebp
        mov ebpesp
        ;Need to sub esp locals at some point...?

        mov ecx, [ebp+8]
        mov edx, [ebp+12]
        label .listAddress dword at ebp-4
        label .newItemAddress dword at ebp-8
        label .afterNewItemAddress dword at ebp-12
        label .hHeap dword at ebp-16
        label .hAllocatedMemory dword at ebp-20
        label .newListItem ListItem at ebp-24 ;?

        
        push ebx esi edi

        mov [newNextItem.listAddress], ecx
        mov [newNextItem.newItemAddress], edx




So I have been using the non-Windows strucs so far. They seem to work for what I have needed.

Appreciated!
Post 10 Aug 2016, 15:55
View user's profile Send private message Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 15301
Location: Bigweld Industries
Okay, so in that case within your function you can use:

Code:
virtual at ebp-stackSize
  .localStruc1 MyStruc1
  .localStruc2 MyStruc2
end virtual

Post 10 Aug 2016, 16:14
View user's profile Send private message Visit poster's website Reply with quote
donn



Joined: 05 Mar 2010
Posts: 67
OK, I think this needs a little more testing but the function results I am currently seeing are correct. Here's how I started it based on what you said:


Code:

;------------
;   Inserts item at the current position index.
;   Updates list item count, item previous and next addresses, etc.
;   Takes List address, item address as parameters
;------------
newNextItem:
        push ebp 
        mov ebpesp 
        sub esp, ((4*6)+(4*5))

        mov ecx, [ebp+8
        mov edx, [ebp+12
        label .listAddress dword at ebp-4 
        label .newItemAddress dword at ebp-8 
        label .afterNewItemAddress dword at ebp-12
        label .beforeNewItemAddress dword at ebp-16 
        label .hHeap dword at ebp-20 
        label .hAllocatedMemory dword at ebp-24 
        virtual at ebp-44
                .newListItem ListItem
        end virtual



        push ebx esi edi

        mov [newNextItem.listAddress], ecx
        mov [newNextItem.newItemAddress], edx




It was working yesterday with one function call (inserting one List Item), but a second call wiped out the original List contents. Have other functions which append items to the end and an untested remove function, but they use the global strucs when HeapAlloc is not needed.

Will eventually convert the globals to this new stack-local style soon and maybe eventually go the multithreading route.

Thank you for the help!
Post 10 Aug 2016, 18:48
View user's profile Send private message Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 15301
Location: Bigweld Industries
You can define all your variables inside the virtual block:

Code:
virtual at ebp-something
        .listAddress            dd ?
        .newItemAddress         dd ?
        .afterNewItemAddress    dd ?
        .beforeNewItemAddress   dd ?
        .hHeap                  dd ?
        .hAllocatedMemory       dd ?
        .newListItem            ListItem
end virtual

Post 10 Aug 2016, 18:58
View user's profile Send private message Visit poster's website Reply with quote
donn



Joined: 05 Mar 2010
Posts: 67
That would remove the need to calculate some ebp offsets manually, good idea!
Post 10 Aug 2016, 20:01
View user's profile Send private message Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 15301
Location: Bigweld Industries
You can also compute the size automatically (I didn't test this yet):

Code:
sub esp,.theSize
virtual at ebp-.theSize
        .listAddress            dd ?
        .newItemAddress         dd ?
        .afterNewItemAddress    dd ?
        .beforeNewItemAddress   dd ?
        .hHeap                  dd ?
        .hAllocatedMemory       dd ?
        .newListItem            ListItem
        .theSize = $-$$
end virtual

Post 10 Aug 2016, 20:07
View user's profile Send private message Visit poster's website 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


Powered by phpBB © 2001-2005 phpBB Group.

Main index   Download   Documentation   Examples   Message board
Copyright © 2004-2016, Tomasz Grysztar.