Skip to content

Instantly share code, notes, and snippets.

@chendo
Created September 12, 2013 04:50
Show Gist options
  • Save chendo/6533177 to your computer and use it in GitHub Desktop.
Save chendo/6533177 to your computer and use it in GitHub Desktop.
My first assembly! Wrote a bootloader that just prints gibberish in colours. I tried to slow it down but couldn't figure out the interrupt handler stuff.
use16
org 0x7c00
xor ax, ax
xor bx, bx
xor cx, cx
xor dx, dx
mov ds, ax
mov fs, ax
mov ss, ax
mov sp, 0x7bfe
mov ax, 0xb800
mov fs, ax
cli
mov [bx+0x20], word timer_handler
mov [bx+0x22], word 0
mov al, 0x36
out 0x43, al
%define divisor (1193180 / 50)
mov al, divisor & 0xff
out 0x40, al
mov al, (divisor >> 8) & 0xff
out 0x40, al
sti
disco:
call rand
mov [fs:bx], al
mov [fs:bx + 1], ah
add bx, 2
cmp bx, 80 * 25 * 2
mov eax, 0xffffffff
call sleep
jl disco
mov bx, 0
jmp disco
rand:
rdtsc
ret
tick:
dd 0
sleep:
mov [tick], eax
.loop:
mov eax, [tick]
cmp eax, 0
jg .loop
ret
timer_handler:
push eax
mov eax, [tick]
cmp eax, 0
je .finish
dec dword [tick]
.finish:
mov al, 0x20
out 0x20, al
pop eax
iret
times 510-($-$$) db 0
db 0x55
db 0xaa
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment