;=============================================================== ; BOOT SECTOR ; [http://www.karig.net/0012.html] ;=============================================================== [ORG 0x7C00] [BITS 16] main: ; ------ Straighten out segment registers. ; ------ [http://www.karig.net/0002.html] jmp word 0:segzero segzero: mov ax, cs mov ds, ax mov es, ax mov fs, ax mov gs, ax ; ------ Set up call stack. cli mov ax, 0x1000 mov ss, ax mov sp, 0xFFFE sti ; ------ Clear text screen. ; ------ [http://www.karig.net/0011.html] ; set 80x25 text mode and clear screen mov ax, 3 int 0x10 ; ------ Set up data stack. ; ------ [http://www.karig.net/0012.html] mov si, stack_top lodsb ; ------ Test c_comma and dump results. ; ------ [http://www.karig.net/0012.html] mov cx, 48 .1: call c_comma dec cx jnz .1 mov bx, 0x8000 call dump_16 call dump_16 call dump_16 ; ------ Halt computer. jmp short $ ; VARIABLES: here: dw 0x8000 stack_top: db 0x05, 0x16, 0x27, 0x38, 0x49, 0x5A, 0x6B, 0x7C db 0x8D, 0x9E, 0xAF, 0xB0, 0xC1, 0xD2, 0xE3, 0xF4 db 0xD0, 0xEF, 0xFE, 0x0D, 0x1C, 0x2B, 0x3A, 0x49 db 0x58, 0x67, 0x76, 0x85, 0x94, 0xA3, 0xB2, 0xC1 db 0x12, 0x34, 0x56, 0x78, 0x9A, 0xBC, 0xDE, 0xF0 db 0x23, 0x45, 0x67, 0x89, 0xAB, 0xCD, 0xEF, 0x01 stack_bottom: db 0, 0 ; ROUTINE: c_comma ; ------ [http://www.karig.net/0012.html] c_comma: mov bx, [here] mov [bx], al inc bx mov [here], bx lodsb ret ; ROUTINES to print to the screen. ; ------ [http://www.karig.net/0008.html] clear_screen: mov ax, 3 int 0x10 xor bh, bh xor dx, dx mov ah, 2 int 0x10 ret ; ------ [http://www.karig.net/000f.html] scroll_up: mov bh, 7 xor cx, cx mov dx, (24*0x100) + 79 mov ax, (0x0600 + 1) int 0x10 ret ; ROUTINES needed to support hex dumps. ; ------ [http://www.karig.net/0009.html] byte_to_hex: xor bh, bh mov bl, al and bl, 0x0F mov ah, [.digits + bx] mov bl, al shr bl, 4 mov al, [.digits + bx] ret .digits: db "0123456789ABCDEF" print_colon: mov al, ':' jmp print_char print_space: mov al, ' ' jmp print_char print_vbar: mov al, '|' jmp print_char print_word: ; pass word in AX push ax mov al, ah call print_byte pop ax print_byte: ; pass byte in AL call byte_to_hex push ax call print_char pop ax mov al, ah ;jmp print_char print_char: xor bh, bh xor cx, cx inc cx mov ah, 0x0A int 0x10 get_pos: xor bh, bh mov ah, 3 int 0x10 next_column: inc dl cmp dl, 80 jb set_pos next_row: xor dl, dl inc dh cmp dh, 25 jb set_pos dec dh push dx call scroll_up pop dx set_pos: xor bh, bh mov ah, 2 int 0x10 ret ; ROUTINE to dump bytes to the screen. ; ------ [http://www.karig.net/0009.html] dump_16: push bx mov ax, fs call print_word call print_colon pop ax push ax call print_word call print_colon call print_space pop bx xor si, si .1: mov al, [fs:bx+si] push si push bx call print_byte call print_space pop bx pop si inc si cmp si, 16 jb .1 push bx call print_vbar call print_space pop bx xor si, si .2: mov al, [fs:bx+si] push si push bx call print_char pop bx pop si inc si cmp si, 16 jb .2 push bx call get_pos call next_row pop bx add bx, 16 ret ; ------ (Required to make this a boot sector.) ; ------ [http://www.karig.net/000d.html] times 508 - ($-$$) db 0x90 ; nop jmp short $+4 db 0x55, 0xAA