Last active
January 6, 2024 19:23
-
-
Save nicdgonzalez/997bdfc36c01e5724b2d36385d7994d2 to your computer and use it in GitHub Desktop.
"Hello, World!" in x86-64 Assembly for the BIOS environment. Written from scratch (no tutorials). I'm proud of it, but not proud enough for it to go in it's own repository; instead, it will live here in a Gist instead.
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
[BITS 16] ; 16-bit code | |
[ORG 0x7C00] ; BIOS loads the boot sector at 0x7C00 | |
jmp start ; Jump to the `start` label | |
message db "Hello, World!", 0 ; The message to print | |
length equ ($ - message) ; The length of `message` (difference of the | |
; current address and the address of `message`) | |
start: | |
mov si, message ; Load the address of `message` into SI | |
xor bx, bx ; Zero out BX to use it as a counter | |
mov cx, length ; Load the length of the message into CX | |
mov ah, 0x0E ; TeleType (TTY) output function | |
next: | |
mov al, byte [si + bx] ; Dereference the address of (`message` + BX) | |
int 0x10 ; Call BIOS interrupt 0x10 (TTY output) | |
inc bx ; Increment BX to point to the next character | |
cmp bx, cx ; Have we reached the specified length? | |
jne next ; If not, jump back to `next` | |
end: | |
jmp $ ; Infinite loop | |
times 510 - ($ - $$) db 0 ; Pad the rest of the boot sector with zeros | |
dw 0xAA55 ; Boot signature (A.K.A. magic number) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment