Commit e85e6bb9 by triazo

Add hex printing function, hex print hello world

parent 10f6f815
Showing with 50 additions and 6 deletions
...@@ -14,11 +14,11 @@ st: ...@@ -14,11 +14,11 @@ st:
mov cx, 0x0002 ; floppy cylinder mov cx, 0x0002 ; floppy cylinder
call read_sectors_16 ; read with above args call read_sectors_16 ; read with above args
jnc 0x7e00 ; jump to actual code jnc 0x7e00 ; jump to actual code
halt: halt:
cli ; halt if failed, loop cli ; halt if failed, loop
hlt hlt
jmp halt jmp halt
read_sectors_16: read_sectors_16:
pusha pusha
mov si, 0x02 ; maximum attempts - 1 mov si, 0x02 ; maximum attempts - 1
...@@ -34,7 +34,7 @@ read_sectors_16: ...@@ -34,7 +34,7 @@ read_sectors_16:
.end: .end:
popa popa
retn retn
read_fail db 'Failure to read from disk.', 13, 10, 0 read_fail db 'Failure to read from disk.', 13, 10, 0
; $ is current line, $$ is first line, db 0 is a 00000000 byte ; $ is current line, $$ is first line, db 0 is a 00000000 byte
; So, pad the code with 0s until you reach 510 bytes ; So, pad the code with 0s until you reach 510 bytes
...@@ -44,8 +44,10 @@ times 510 - ($ - $$) db 0 ...@@ -44,8 +44,10 @@ times 510 - ($ - $$) db 0
;---------------- BOOTLOADER CODE ----------------; ;---------------- BOOTLOADER CODE ----------------;
ls: mov si, str1 ; pointer to string in si ls: mov si, str1 ; pointer to string in si
call PrintStr ; print string call PrintStr ; print string
jmp Main ; call PrintHexStr ; print string
jmp Main ;
hlt hlt
;---------------- SCREEN FUNCTIONS ---------------; ;---------------- SCREEN FUNCTIONS ---------------;
PrintStr: ; print string at SI PrintStr: ; print string at SI
nextChar: nextChar:
...@@ -64,11 +66,53 @@ PrintChar: ; print char at AL ...@@ -64,11 +66,53 @@ PrintChar: ; print char at AL
mov bl, 0x07 ; light gray mov bl, 0x07 ; light gray
int 0x10 ; print character int 0x10 ; print character
ret ret
;------------------ DATA BLOCK ------------------; MOV AH, 0x0E ; Teletype Mode
MOV BH, 0x00 ; Page zero
MOV BL, 0x07 ; Light Gray
INT 0x10 ; Print Character
RET
PrintHexStr:
nexthchar:
mov al, [si] ; grab next char
or al, al ; if char is null term
jz exith ; then return
call PrintHexChar ; else print char
inc si ; inc pointer to next char
jmp nexthchar ; loop
exith:
ret
str1 db 'Hello World', 0 ;stuff PrintHexChar:
;; call PrintChar
mov cl, al
mov bl, al
and bl, 0xf0
shr bl, 4
mov al, BYTE [hexChars + ebx]
call PrintChar
mov bl, cl
and bl, 0x0f
mov al, BYTE [hexChars + ebx]
call PrintChar
ret
;------------------ DATA BLOCK ------------------;
str1 db 'Hello World', 0 ; Hello World
str2 db 'WHY IS THIS', 0 str2 db 'WHY IS THIS', 0
hexChars db '0123456789abcdef' ; Used for hex formatting
;-------------- PADDING / SIGNATURE -------------;
; $ is current line, $$ is first line, db 0 is a 00000000 byte
; So, pad the code with 0s until you reach 510 bytes
TIMES 510 - ($ - $$) DB 0
; Fill last two bytes (a word) with the MBR signature 0xAA55
DW 0xAA55
>>>>>>> Add hex printing function, hex print hello world
Main: ;main section Main: ;main section
nop nop
nop nop
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment