I can't get my simple “Hello World” program (see below) to run in x86_64 assembly!
I read the section in the developers handbook, browsed the web and used information in this thread: assembly-simple-hello-world
… and came up with the following:
I assembled it with the following command, which executes without error:
When executing hello_world nothing appears on the console and the exit code is
The output of
Using
What did I do wrong?
I read the section in the developers handbook, browsed the web and used information in this thread: assembly-simple-hello-world
… and came up with the following:
Code:
.section .rodata
msg:
.ascii "Hello World!\n"
.section .text
.global _start
_start:
movq $1, %rax # SYS_write
movq $1, %rdi # STDOUT
movabsq $msg, %rsi # Output buffer
movq $13, %rdx # length
syscall
movq $60, %rax # SYS_exit
movq $0, %rdi # EXIT_SUCCESS
syscall
I assembled it with the following command, which executes without error:
Code:
cc -g -x assembler -static -nostartfiles -nostdlib hello_world.s -o hello_world
When executing hello_world nothing appears on the console and the exit code is
1The output of
objdump -d ./hello_world looks ok to me:
Code:
hello_world: file format elf64-x86-64
Disassembly of section .text:
0000000000201130 <_start>:
201130: 48 c7 c0 01 00 00 00 movq $0x1, %rax
201137: 48 c7 c7 01 00 00 00 movq $0x1, %rdi
20113e: 48 be 20 01 20 00 00 00 00 00 movabsq $0x200120, %rsi # imm = 0x200120
201148: 48 c7 c2 0d 00 00 00 movq $0xd, %rdx
20114f: 0f 05 syscall
201151: 48 c7 c0 3c 00 00 00 movq $0x3c, %rax
201158: 48 c7 c7 00 00 00 00 movq $0x0, %rdi
20115f: 0f 05 syscall
Using
lldb to find out what's going on I discovered that the first syscall exits the process.What did I do wrong?