flat assembler
Message board for the users of flat assembler.
![]() |
Author |
|
donn 21 Dec 2015, 17:10
Hi,
I'm continuing with an attempt to build a Linked List in asm. Also would like it accessible from C. I'm able to use an asm function to load the List struc with default values. However, when I define a second List in C, and set a struc member, such as isBlankList, it sets the value for both Lists. Is there a way for separate Lists to be defined as needed, from C? What I have so far: ASM struc definition, C header also has one without default values Code: struc List{ .firstItem dd ? .listSize dd ? .index dd ? .isBlankList dd 1 ; Used value of 50 when testing as a more unique value } ASM newList function Code: newList: push ebp mov ebp, esp mov ecx, [ebp+8] mov edx, [ebp+12] push ebx esi edi mov eax, .newListLocal ; Pass newly defined List address? pop edi esi ebx mov esp, ebp pop ebp retn 0 .newListLocal: ; This may be the problem. It seems to set default values for list List ; one List, but with two, changes are mirrored to each. C Lists being defined, and loaded with default values Code: List *asmList = (List*)newList(); List *asmList2 = (List*)newList(); asmList->isBlankList = 10; // Value of 10 used during testing as a more unique value. // After setting this, both asmList and asmList2 have 10 // for the isBlankList member. Beforehand, they had 1 // or whatever was specified in ASM definition. Thanks a lot
|
|||||||||||
![]() |
|
donn 21 Dec 2015, 22:56
Thanks a lot. Will go the Kernel32 API route for now.
|
|||
![]() |
|
donn 21 Feb 2016, 19:09
Got it, solved for now:
Code: newList: push ebp mov ebp, esp mov ecx, [ebp+8] mov edx, [ebp+12] push ebx esi edi call [GetProcessHeap] mov [hHeap], eax ;Size of List push 000001100b ;Set allocated to 0s push 000001000b push [hHeap] call [HeapAlloc] mov [hAllocatedMemory], eax mov dword ebx, [hAllocatedMemory] ;Define a local List, members become initialized since we have a definition (shown below) list List ;Start moving over the local values. Since struc was used, we can reference them with labels. Also, they are initialized. mov dword edx, [list] mov dword [ebx], edx mov dword edx, [list.index] mov dword [ebx+4], edx mov dword edx, [list.isBlankList] mov dword [ebx+8], edx ;Return the handle mov eax, [hAllocatedMemory] pop edi esi ebx mov esp, ebp pop ebp retn 0 And the struc: Code: struc List{ .listSize dd 2 .index dd 1 .isBlankList dd 50 } Plenty new to learn going forward, like maybe using $ for sizing and how to mov the local struc memory values before they get wiped out. Rep and some of the strings instructions may solve that regardless of the struc layout, but want to investigate the options. Thanks again. |
|||
![]() |
|
< Last Thread | Next Thread > |
Forum Rules:
|
Copyright © 1999-2025, Tomasz Grysztar. Also on GitHub, YouTube.
Website powered by rwasa.