From f6c0dc9ded1effff4546e2da236d719eae922b43 Mon Sep 17 00:00:00 2001 From: Kiril Kovachev Date: Fri, 31 Jan 2025 23:27:41 +0000 Subject: [PATCH] Add hello-world example assembly program --- doc/examples/hello.asm | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) create mode 100644 doc/examples/hello.asm diff --git a/doc/examples/hello.asm b/doc/examples/hello.asm new file mode 100644 index 0000000..3a35c4d --- /dev/null +++ b/doc/examples/hello.asm @@ -0,0 +1,19 @@ +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 +