I am trying to allocate 40 bytes of space in memory through calling the external C command malloc in x86 Assembly (AT&T/Intel syntax). However, when I debug my program, the EAX register has not changed after the malloc command is called (from my understanding, the procedure to use malloc is to put the number of bytes you want to allocate in the EDI register and then executing call malloc to put the pointer to the block of memory allocated in the EAX register). Below is my x86 Assembly code:
.extern malloc
.text
.global main
main:
movl %esp, %ebp #for correct debugging
# write your code here
xorl %eax, %eax
movl $40, %edi
call malloc
ret
I am using 32-bit convention (not 64-bit) on Linux.
Compilation command:
gcc -m32 -Wall -g -c -o program.o program.s