Skip to content

Instantly share code, notes, and snippets.

@cedriczirtacic
Last active April 30, 2018 17:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cedriczirtacic/916cb2751423b50bab39595aa71a51d3 to your computer and use it in GitHub Desktop.
Save cedriczirtacic/916cb2751423b50bab39595aa71a51d3 to your computer and use it in GitHub Desktop.
/*
all:
as -o test.o mbr.S
objcopy -O binary test.o test.bin
dd if=test.bin of=test.img skip=31744 bs=1 count=512
*/
.code16
.org 0x7c00
.macro sleep
movw $0x4280, %dx
movw $0x000f, %cx
movb $0x86, %ah
int $0x15
.endm
.macro print_char, char
//get cursor info
movb $0x03, %ah
xorb %bh, %bh
int $0x10
//move 1 position
addb $1, %dl
//set position
movb $0x02, %ah
int $0x10
//print char
movb $0x40, %ah
movb \char, %al
stosw
.endm
.macro clear
movw $0x07d0, %cx
//fg=black,bg=red
movw $0x4000, %ax
xor %di, %di
rep stosw
// set cursor to 0 position
movb $0x02, %ah
xorw %dx, %dx
int $0x10
.endm
xorw %ax, %ax
movw %ax, %ds
cli
// text mode
movw $0xb800, %ax
movw %ax, %es
//set cursor shape
movb $0x01, %ah
movw $0x2607, %cx
int $0x10
movb $0x03, %ah
int $0x10
clear
repeat:
xorw %ax, %ax
xorw %di, %di
rdtsc
andw $0x06ff, %ax
movw %ax, %di
print_char $'C'
sleep
print_char $'e'
sleep
print_char $'d'
sleep
print_char $'r'
sleep
print_char $'i'
sleep
print_char $'c'
sleep
clear
//let's wait for an <Enter> to
//print the next set
wait:
movb $0x00, %ah
int $0x16
cmp $28, %ah
jne wait
jmp repeat
.org 0x7dfe,0
.byte 0x55, 0xAA
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment