flat assembler
Message board for the users of flat assembler.
Index
> Windows > Pointers on Structs |
Author |
|
JohnFound 08 Mar 2005, 13:55
Well, if you have some variable in static memory, you can use it this way:
Code: struct PERSON .name rb 100 .age dd ? ends SomeVar PERSON mov [SomeVar.age], 1000 ; if you have pointer to the variable of the type PERSON, let say obtained ; on dynamic memory allocation or some calculations and this pointer is ; stored in register (edx for example): mov [edx+PERSON.age], 1000 ; will do the job ; if the pointer is stored in some variable, you need to load it into some ; register (C will do the same, only hidding it from you) mov eax, [ptrMyself] ; now eax points to some structure of PERSON type. mov [eax+PERSON.age], 1000 ; so use it... I hope this helps you. Regards. |
|||
08 Mar 2005, 13:55 |
|
denial 08 Mar 2005, 18:46
Thank you, it really helped me.
|
|||
08 Mar 2005, 18:46 |
|
denial 08 Mar 2005, 19:47
Sorry for double-posting, however I've got yet another problem. Your method works well with DWORDS, but with strings, I got a problem because I don't know how to pass the address to the function wsprintf
Code: mov ebx,[_SomeVar] ;my var mov ebx,[ebx+PERSON.name] cinvoke wsprintf,ebx,'%s',"Somebody " This doesn't work. I tried it with LEA. Then it compiled but nothing happened. Can you help me out please? |
|||
08 Mar 2005, 19:47 |
|
denial 10 Mar 2005, 11:56
Can nobody help? :O(
|
|||
10 Mar 2005, 11:56 |
|
rea 10 Mar 2005, 17:06
Supose taht you have something like....
Code: struc x .resd e1 .resd e2 .resd e3 endstruc that define a model for access memory. that model say that at displacement 0 you will "interprett" like e1, displacement at 4 from the start of the memory you will interpretit like e2, in fact this displacements are defined as follows.... Code: x.e1 = 0 x.e2 = 4 x.e3 = 8 Now supose that you whant to access at memory m with this modelation of memory, m is located at 0x100, this model wil let you access like this: Code: m+x.e1 = 0x100+0x0 = 0x100 m+x.e2 = 0x100+0x4 = 0x104 m+x.e3 = 0x100+0x8 = 0x108 each location in memory have something. Before I explain the next, for what lea and mov act in the same way with any memory location that I have put in data, code or bss see that Im not including the ones at heap and stack, because the first group have fixed locations and can be calculated by the assembler, and because is a inmediate number, will be loaded at the respective displacement taking the respective segment (in plain memory they ahve the same value), that is you can use mov eax, memory and because memory is ixed (or a single number.. the calculation of such number is left to the assembler) and is for that lea work exactly the same way with this memory locations. But you can not move some like mov eax, memory+4, in this case is where you use lea . Now pheraphs you are questionating for what lea uses this sintaxis: lea eax, [memory...], because you are saying: load effective address in eax of this content in memory, that is lea eax, [memory], because [] indicate the content of such memory. The second group the stack and the heap can not be calculated by the assembler. The allocation functions return a sngle number that can be moved with mov. The stack is a combination of a register and a displacement, this is way you can not move the memory location directly, and you se lea for calculate it... Anyway you can have a humber of a memory location in a register, memory or direct(only posible when the assembler where able to calculate it) OK, lets continue. Now m is at 0x100 you can save a memory location of a string like this... Code: mov ebx, numberOfMemory mov [m+x.e3], ebx Where numberOfmemory can be obtained from lea, from a direct number(provided by the assembler) or from a allocation function. or pass this value previously saved to the function that require the value saved there (that represent a memory location) mov eax, [m+x.e3] cinvk wsprintf, eax, "%s", "aName" and is what you do... the point is that this function si writing the output string at the location pointed by eax.. you havent tried to print such location?? some ike: invk MessageBoxA, NULL, eax, eax, MB_OK ????? That should work .. sure if you previously save the memory location in m+x.e3 . |
|||
10 Mar 2005, 17:06 |
|
denial 10 Mar 2005, 18:44
Oh god I'm stupid... ok now it works. I made some string-operations and I made it the right way. But when I tested with MsgBox, I passed the wrong address so the string didn't appear. Ah! Silly Newbie-Mistake ;O)
I'll get better, I promiss. Thank you very much for your detailed help. :O))) |
|||
10 Mar 2005, 18:44 |
|
rea 11 Mar 2005, 14:59
Some times hapend , you know.
Keep in touch . |
|||
11 Mar 2005, 14:59 |
|
< Last Thread | Next Thread > |
Forum Rules:
|
Copyright © 1999-2024, Tomasz Grysztar. Also on GitHub, YouTube.
Website powered by rwasa.