Reputation: 1456
I am looking a paper Size Is EverythingSize Is Everything with kernel 3.8.4 x64 nasm gcc-4.7.2 fedora
by type in moretiny.asm
BITS 64
EXTERN _exit
GLOBAL _start
SECTION .text
_start:
push dword 42
call _exit
\>nasm -f elf64 moretiny.asm
\>gcc -Wall -s -nostartfiles -o moretiny.
\>./a.out ; echo $?
7
With gdb help . break at _exit
(gdb) display /i $pc
1: x/i $pc
=> 0x3a5e0bb750 <_exit>: movslq %edi,%rdx
(gdb) si
0x0000003a5e0bb753 in _exit () from /lib64/libc.so.6
1: x/i $pc
=> 0x3a5e0bb753 <_exit+3>: mov 0x2f56de(%rip),%r10 # 0x3a5e3b0e38
(gdb)
0x0000003a5e0bb75a in _exit () from /lib64/libc.so.6
1: x/i $pc
=> 0x3a5e0bb75a <_exit+10>: mov $0xe7,%r9d
(gdb)
0x0000003a5e0bb760 in _exit () from /lib64/libc.so.6
1: x/i $pc
=> 0x3a5e0bb760 <_exit+16>: mov $0x3c,%r8d
(gdb)
0x0000003a5e0bb766 in _exit () from /lib64/libc.so.6
1: x/i $pc
=> 0x3a5e0bb766 <_exit+22>: jmp 0x3a5e0bb781 <_exit+49>
(gdb)
0x0000003a5e0bb781 in _exit () from /lib64/libc.so.6
1: x/i $pc
=> 0x3a5e0bb781 <_exit+49>: mov %rdx,%rdi
(gdb)
0x0000003a5e0bb784 in _exit () from /lib64/libc.so.6
1: x/i $pc
=> 0x3a5e0bb784 <_exit+52>: mov %r9d,%eax
(gdb)
0x0000003a5e0bb787 in _exit () from /lib64/libc.so.6
1: x/i $pc
=> 0x3a5e0bb787 <_exit+55>: syscall
(gdb)
[Inferior 1 (process 32082) exited with code 07]
seem like the syscall return the code with 07 , I am not sure why .
Upvotes: 2
Views: 190
Reputation: 94729
The x86_64
abi specifies the parameter passing convention.
In this case:
If the class is INTEGER, the next available register of the sequence %rdi, %rsi, %rdx, %rcx, %r8 and %r9 is used12 .
so you should use the %rdi
register instead of pushing onto the stack.
This is quite evident from your single-step debugging into the _exit
function call.
Upvotes: 3