Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ;;;; bootloader.asm
- ;;;; Bootloader for the OS
- org 0x7c00
- bits 16
- ;;; Start/main function
- start:
- jmp boot
- ;;; Includes
- %include "io.asm"
- ;;; Boot function
- boot:
- cli ; no interrupts
- cld ; only thing needed to init
- mov dh, 5 ; move decimal 5 into dh (row)
- mov dl, 5 ; move decimal 5 into dl (column)
- call movCursor ; call movCursor
- call print ; call putChar
- hlt ; halt the OS
- ;;; 512 available bytes, clear the rest with 0
- times 510 - ($-$$) db 0
- dw 0xAA55 ; Boot signature
- ;;;; io.asm
- ;;;; IO subroutines/functions for the OS
- movCursor:
- ; dh = Y coord, dl = X coord, bh = page #
- ; void return
- mov ah, 02h ; move 0x02 into ah
- mov bh, 0 ; move decimal 0 into bh (page number)
- or dh, 5 ; if dh != 5
- jnz incCursorPosH ; jump to incCursorPosH
- int 0x10 ; call
- add dh, 1 ; increase register dh by 1
- ret
- incCursorPosH:
- ; dh = row #
- ; void return
- add dh, 1 ; increase register dh by one
- int 0x10 ; call
- ret
- incCursorPosV:
- ; not needed right now
- ; dl = column #
- ; void return
- add dl, 1 ; increase register dl by one
- int 0x10 ; call
- ret
- putChar:
- ; al = char, bl = text color, cx = # of times printed
- ; bh = page number
- ; void return
- lodsb ; load a byte from si
- or al, al ; OR to check al
- jz done ; if 0, there's nothingo left for the string, so end
- mov ah, 0eh ; move 0x0a into ah
- mov bh, 0 ; move decimal to page number of register bh
- mov bl, 4 ; move decimal 4 to text color of register bl
- mov cx, 1 ; move decimal 1 into cx (print character once)
- int 10h ; call
- call movCursor ; call movCursor and go the next position
- jmp putChar ; loop back & restart putChar
- done:
- ret
- print:
- ; ds:si = null-terminated string
- ; void return
- mov ax, 0x07c0 ; move 0x07c0 into ax
- mov ds, ax ; move that segment into ds (segment)
- mov si, message ; move the message into si (offset)
- call putChar ; call putChar
- call movCursor ; call movCursor
- ;;; Variables
- message db 'Hello World', 0
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement