0

I had just started to learn assembly and some lower level concepts (I have some higher level background with python, js, etc).

I am trying to print out hello world with the following assembly program:

section .data
    msg db 'Hello World'
    len equ $ - msg

section .text
    global _start

_start:
    MOV rdi, 1 ; stdin fd
    MOV rsi, msg
    MOV rdx, len
    MOV rax, 1 ; write syscall
    INT 0x80

I am running Ubuntu Linux on an x86_64 machine.

I assembled the program with nasm: nasm -f elf64 hello_world.nasm

Then I then linked with ld: ld -o hello_world hello_world.o

When I run ./hello_world nothing is printed out to the console.

jon doe
  • 460
  • 1
  • 7
  • Where did you get this code from? Why are you using `int 0x80` to do a 64 bit system call? – fuz Mar 22 '22 at 16:03
  • I just looked at a bunch of guides online and tried to do something on my own. What would be the correct way to do it? – jon doe Mar 22 '22 at 16:08
  • 1
    Use a `syscall` instruction. `int 0x80` is for 32 bit mode. You'll also need to add an exit system call after the write system call so your program actually terminates the normal way. – fuz Mar 22 '22 at 16:08
  • There's some discussion [here](https://stackoverflow.com/a/46087731/2189500), but in general, 64bit should use syscall, not int 80. Note: The function numbers and registers are different for syscall than int 80. – David Wohlferd Mar 22 '22 at 16:09
  • You have the call-number and arg registers for the 64-bit `syscall` ABI, but then you used `int 0x80` which looks at EBX, ECX, and EDX. (And where EAX=1 is `_exit`). Just replace it with `syscall`! On an-to-date system, `strace ./hello_world` should properly decode the 32-bit system call you make. – Peter Cordes Mar 22 '22 at 18:27

0 Answers0