I am trying to learn the x86_64 assembly and am using GCC as my assembler. The exact command I use is:
gcc -nostdlib tapydn.S -D__ASSEMBLY__
I mainly use gcc for my preprocessor. Here tapydn.S:
.global _start
syscall=0x80
.text
_start:
movl $__NR_exit, %eax
movl $0x00, %ebx
int $syscall
This results in a segmentation error. I believe the problem is with the following line:
movl $__NR_exit, %eax
I used __NR_exitbecause it was more visual than some magic number. However, it seems that its use is incorrect. I believe this is so, because when I change the corresponding line to the following, it works fine:
movl $0x01, %eax
Further support for this trace of thought is content usr/include/asm-generic/unistd.h:
#define __NR_exit 93
__SYSCALL(__NR_exit, sys_exit)
, __NR_exit 1, 93! , , , . , $0x01 ( undefined ++), ...
sys_exit. . ( $):
movl $sys_exit, %eax
:
/tmp/cc7tEUtC.o: In function `_start':
(.text+0x1): undefined reference to `sys_exit'
collect2: error: ld returned 1 exit status
, , - -nostdlib GCC. , .
Jester 32 64 0x3C, :
movq $0x3C, %eax
movq $0x00, %ebx
. eax ebx rax rbx:
movq $0x3C, %rax
movq $0x00, %rbx
.
Jester , syscall, int $0x80:
.global _start
.text
_start:
movq $0x3C, %rax
movq $0x00, %rbx
syscall
, , rdi rbx System V AMD64 ABI:
movq $0x00, %rdi
, , 0x3C .
, :