0

I'm new to assembly, so I do not quite understand why my program does not work. It crashes through SIGSEGV. Here code of my test.asm file:

section .text
    global _start
_start:
    push word 0x4f4b
    mov al, 4
    mov bl, 1
    mov rcx, rsp
    mov dl, 2
    int 0x80      ; writes 'OK' message into STDOUT

    mov al, 1
    mov bl, 0
    int 0x80      ; exit with code 0


Commands:

$ nasm -f elf64 test.asm
$ ld -s -o test test.o
$ ./test


OS: Ubuntu 17.10 x64

  • Use a debugger. The high bytes of `rax` will be all be `0xff` after the 32-bit system call returns `-EFAULT`, so `eax=0xFFFFFF01` / `int 0x80` returns `-ENOSYS` instead of exiting, and then you execute whatever bytes are next. – Peter Cordes Mar 14 '18 at 11:47
  • Oh, I prefer to use **syscall** to use all the features of the x64 processor. Thanks for your comment – Michael Proshchuk Mar 14 '18 at 12:08
  • @МихайлоПрощук If you are writing a 64 bit program, you need to use the `syscall` based system calls. – fuz Mar 14 '18 at 14:58

0 Answers0