Due to the following topic, Initializing a struct in win32 assembly programming using MASM

I tried to correct my mistakes, So I tried the following code :

.model flat,stdcall
option casemap:none

struct1 struct
first db ?
second dd ?
third db ?
struct1 EndS

Initializedstructure struct1 <4,10>

mov eax, struct1.first
mov ebx , struct1.second
mov ecx , struct1.third
mov eax , offset struct1.first
mov ebx , offset struct1.second
mov ecx , offset struct1.third
end start

But on the disassembled code didn't find any thing. I added the offset of each struct's member to distinguish the differences between the two.

.text:00401000 start:
.text:00401000                 mov     eax, 0
.text:00401005                 mov     ebx, 1
.text:0040100A                 mov     ecx, 5
.text:0040100F                 mov     eax, 0
.text:00401014                 mov     ebx, 1
.text:00401019                 mov     ecx, 5

I've surfed the net but didn't find any documentation describing the use of structs well, so I decided to try it by myself. The disassembled code seems,it holds the size of each struct's member.

The main question is how to use the members of the struct within the code?

1 Answer 1


In this case struct1 is such a general structure should be initialized to use, otherwise such this statement : mov eax , struct1.second just gives you the offset of struct1 from the begging. I think you've misunderstood the Initializedstructure to an instruction or other directives.You can name it what you want and use the initialized struct in the rest by its name.For instance, in the .data section you would use:

AAAA struct1 <4,10,60>

So in the rest of code in the .code section using following statement will work, mov eax , AAAA.second and give you (in this case) 10 and the mov eax, offset AAAA.second give the offset of second member in run-time.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.