Last active
January 17, 2021 19:38
-
-
Save pyxn/e8b01421123275f9324965fe598a3d53 to your computer and use it in GitHub Desktop.
The Hello World Program on Assembly x86 run on macOS. Tested on M1 MacBook Pro running macOS BigSur 11.1.0.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
; ---------------------------------------------------------------------------------------- | |
; How to compile and run .asm files on macOS: | |
; ---------------------------------------------------------------------------------------- | |
; | |
; 1. Download and open nasm-x.xx.xx-tar.gz from www.nasm.us | |
; 2. Open terminal and change directory to the opened folder | |
; 3. Enter the command "./configure" to run the configure script | |
; 4. Type in the "make" command to build nasm | |
; 5. Type in "sudo make install" to copy the built program to "/usr/bin/nasm" | |
; 6. Add this new directory to the paths file using "sudo nano /etc/paths" | |
; 7. Type in "nasm -ver" to confirm the installation. | |
; 8. Test the hello_world.asm file using: | |
; nasm -f macho64 hello_world.asm | |
; ld -macosx_version_min 10.7.0 -o hello_world hello_world.o | |
; ./hello_world | |
; ---------------------------------------------------------------------------------------- | |
; Writes "Hello, World" to the console using only system calls. Runs on 64-bit macOS only. | |
; ---------------------------------------------------------------------------------------- | |
global start | |
section .text | |
start: | |
mov rax, 0x02000004 ; system call for write | |
mov rdi, 1 ; file handle 1 is stdout | |
mov rsi, message ; address of string to output | |
mov rdx, 13 ; number of bytes | |
syscall ; invoke operating system to do the write | |
mov rax, 0x02000001 ; system call for exit | |
xor rdi, rdi ; exit code 0 | |
syscall ; invoke operating system to exit | |
section .data | |
message: db "Hello, World", 10 ; note the newline at the end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment