So, I'm trying to write x86 to allocate memory for a structure. My c code looks like this:
struc *uno = malloc(sizeof(struc));
uno->first = 0;
uno->second = 0;
uno->third = 0;
struct struc {
int first;
int second;
int *third;
}
And the disassembler looks like ...
pushl %ebp
movl %esp, %ebp
subl $40, %esp
movl $12, (%esp)
call malloc
movl %eax, -12(%ebp)
movl -12(%ebp), %eax
movl $0, (%eax)
movl -12(%ebp), %eax
movl $0, 4(%eax)
movl -12(%ebp), %eax
movl $0, 8(%eax)
movl $0, %eax
So I have a few questions ...
1) The size of the structure is 16, but why does the assembly only show that it highlights 12?
2) What is the point
movl %eax, -12(%ebp)
movl -12(%ebp), %eax
Doesn't that just put the contents of eax in the address of ebp - 12. Then the second statement would be redundant?
3) Why does esp decrease by 40 when there are no other local variables or parameters on the stack? I would think that you only need to reduce 16.
Any help is appreciated, as well as anything I might have missed that you consider relevant. I am new to assembly. Thank.
Awilg source
share