From 8d8b93a828f7b88825421fbd54a9769c51dc65f4 Mon Sep 17 00:00:00 2001 From: dwrz Date: Thu, 16 Mar 2023 00:54:04 +0000 Subject: [PATCH] Add hello-world --- hello-world/hello.s | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) create mode 100644 hello-world/hello.s diff --git a/hello-world/hello.s b/hello-world/hello.s new file mode 100644 index 0000000..50f290e --- /dev/null +++ b/hello-world/hello.s @@ -0,0 +1,27 @@ +# PURPOSE: Print "Hello, World!", then exit. +# INPUT: None. +# OUTPUT: Prints a string to stdout. +# Returns a status code of 0. +# VARIABLES: +# %rax holds the system call number +# %rbx holds the return status +.section .data +hw: + .ascii "Hello, World!" + +.section .text + .globl _start + +_exit: + mov $1, %rax # System call number for exit. + mov $0, %rbx # Exit code. + int $0x80 # Call the kernel. + +_start: + mov $4, %rax # System call number for write. + mov $1, %rbx # stdout. + mov $hw, %rcx # Address of the buffer. + mov $15, %rdx # Number of bytes to write. + int $0x80 # Call the kernel. + +call _exit # Call the _exit macro.