20 lines
904 B
NASM
20 lines
904 B
NASM
global main ; expose the main function to the linker
|
|
section .text ; declare this part of the assembly code to belong to the "text" section, i.e. code section
|
|
|
|
main: ; define a symbolic label, whose address is remembered by the assembler for later
|
|
mov rax, 1 ; SYS_write system call
|
|
mov rdi, 1 ; stdout
|
|
mov rsi, hello ; pointer to start of bytes to write
|
|
mov rdx, 14 ; length of byte string to print
|
|
syscall ; instruction to trap into the OS
|
|
|
|
mov rax, 60 ; SYS_exit system call
|
|
mov rdi, 0 ; 0 exit code - signals success
|
|
syscall ; trap into OS
|
|
; (no return, process exits on the call above)
|
|
|
|
section .rodata ; declare this part of the assembly to belong to the "read-only data" section; on Linux, it is illegal/impossible to write to this area.
|
|
hello:
|
|
db "Hello, world!", 10 ; output raw bytes corresponding to the string into the binary; this can be addressed using the "hello" label
|
|
|