Skip to content

Instantly share code, notes, and snippets.

@nicdgonzalez
Last active January 6, 2024 19:23
Show Gist options
  • Save nicdgonzalez/997bdfc36c01e5724b2d36385d7994d2 to your computer and use it in GitHub Desktop.
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.
[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