Skip to content

Instantly share code, notes, and snippets.

Created January 23, 2016 23:14
Show Gist options
  • Save anonymous/0ddc146f73ff3a13dd35 to your computer and use it in GitHub Desktop.
Save anonymous/0ddc146f73ff3a13dd35 to your computer and use it in GitHub Desktop.
[BITS 16]
[ORG 0x7C00]
jmp 0x0000:start_16 ; In case bootloader is at 0x07C0:0x0000
start_16:
xor ax, ax
mov ds, ax
mov es, ax
cli ; Disable interrupts
mov ss, ax
mov sp, 0x7C00
; sti ; Enable interrupts
; Store the drive number
call dumpregs
mov byte [drive_number], dl
call dumpregs
; PLEASE HALT
jmp $
; No? Please?!... Ok...
; Print message(s)
mov si, msg
call print_string
mov si, msg
call print_string
mov si, msg
call print_string
jmp $ ; HALT
; print_string
; si = string
print_string:
pusha
mov ah, 0x0E
.repeat:
lodsb
cmp al, 0x00
je .done
call dumpregs
int 0x10
call dumpregs
jmp short .repeat
.done:
popa
ret
dumpregs:
push es
pusha
push 0xb800
pop es
mov di, [vidmem_ptr]
mov bp, sp
mov cx, 8
dump_loop:
dec bp
dec bp
mov ax, [bp + 16]
call printhex2
inc di
inc di
loop dump_loop
mov [vidmem_ptr], di
popa
pop es
ret
printhex2:
push ax
mov al, ah
call convhex1
pop ax
convhex1:
aam 16
; DB 0D4h, 16
xchg al, ah
call convhex
mov al, ah
convhex:
cmp al, 10
jb lessthan_10
add al, 'A' - '0' - 10
lessthan_10:
add al, '0'
stosb
mov al, 7
stosb
ret
vidmem_ptr dw 5 * 80 * 2 ; start at row 5
; Variables
drive_number db 0x00
msg db 'TEST',0x0D, 0x0A, 0x00
times 510-($-$$) db 0x00
db 0x55
db 0xAA
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment