Write system call won’t print characters from a register

A quick fix of your code:

push 0x41414141 ; put 'AAAA' into stack memory
mov ecx,esp     ; pointer to the 'AAAA'
mov eax, 4      ; write is syscall 4 for 32-bit Linux
mov ebx, 1      ; stdout
mov edx, 4
int 0x80
add esp,4      ; restore stack

No explanation, as you should first check what I did ask in comment, then the fix will be either obvious, or you will have to ask about something particular you don’t understand…

If you run your original code with strace ./my_program, you’d see write() return -EFAULT because you passed a bad address. Always use strace to debug programs that make syscalls and don’t behave the way you expected.

Leave a Comment