flat assembler
Message board for the users of flat assembler.
Index
> Main > Local struc on stack |
Author |
|
donn 10 Aug 2016, 15:34
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. |
|||
10 Aug 2016, 15:34 |
|
donn 10 Aug 2016, 15:55
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 ebp, esp ;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! |
|||
10 Aug 2016, 15:55 |
|
revolution 10 Aug 2016, 16:14
Okay, so in that case within your function you can use:
Code: virtual at ebp-stackSize
.localStruc1 MyStruc1
.localStruc2 MyStruc2
end virtual |
|||
10 Aug 2016, 16:14 |
|
donn 10 Aug 2016, 18:48
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 ebp, esp 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! |
|||
10 Aug 2016, 18:48 |
|
revolution 10 Aug 2016, 18:58
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 |
|||
10 Aug 2016, 18:58 |
|
donn 10 Aug 2016, 20:01
That would remove the need to calculate some ebp offsets manually, good idea!
|
|||
10 Aug 2016, 20:01 |
|
revolution 10 Aug 2016, 20:07
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 |
|||
10 Aug 2016, 20:07 |
|
< Last Thread | Next Thread > |
Forum Rules:
|
Copyright © 1999-2024, Tomasz Grysztar. Also on GitHub, YouTube.
Website powered by rwasa.