I seem to have an interesting issue, though I am probably doing something blatantly wrong.
My issue is that I am attempting to push AAAABBBBCCCC onto the stack, then print them through stdout. However it seems that in my x86_64 environment the push 0x41414141
pushes 4141414100000000
.
So the following code block:
global _start
section .text
_start:
push 0x43434343 ; CCCC
push 0x42424242 ; BBBB
push 0x41414141 ; AAAA
xor rax,rax ; Zero RAX
mov byte al,0x1 ; 1 for sys_write
mov rdi,rax ; 1 for stdout
mov rsi,rsp ; RSP for source
mov byte dl,0xC ; 12
syscall
xor rax,rax ; Zero RAX
mov al, 0x3C ; 60 for sys_edxit
cdq ; 0 for clean exit.
syscall
Outputs AAAABBBB
, of what I thought was only 8 bytes, was actually the 12 I asked for. When piped to an output file and looked at in hexedit, I noticed it was displaying 414141410000000042424242
.
I figure the push
instruction pushes a dword
value. onto a qword
sized stack? Am I correct in thinking this?
This can be cheeply avoided by taking into account the extra bytes, and changing my length to 20. But that would cause issues with things like sys_open
.
So my question is, what am I doing wrong?