mirror of
https://github.com/cfenollosa/os-tutorial.git
synced 2024-10-27 20:34:19 +00:00
lesson 5 with hex printer
This commit is contained in:
parent
fc73be819b
commit
545546ce5e
@ -110,15 +110,26 @@ The syntax is
|
|||||||
%include "file.asm"
|
%include "file.asm"
|
||||||
```
|
```
|
||||||
|
|
||||||
|
|
||||||
|
Printing hex values
|
||||||
|
-------------------
|
||||||
|
|
||||||
|
In the next lesson we will start reading from disk, so we need some way
|
||||||
|
to make sure that we are reading the correct data. File `boot_sect_print_hex.asm`
|
||||||
|
extends `boot_sect_print.asm` to print hex bytes, not just ASCII chars.
|
||||||
|
|
||||||
|
|
||||||
Code!
|
Code!
|
||||||
-----
|
-----
|
||||||
|
|
||||||
Let's jump to the code. File `boot_sect_print.asm` is the subroutine which will
|
Let's jump to the code. File `boot_sect_print.asm` is the subroutine which will
|
||||||
get `%include`d in the main file. It uses a loop to print bytes on screen.
|
get `%include`d in the main file. It uses a loop to print bytes on screen.
|
||||||
|
It also includes a function to print a newline. The familiar `'\n'` is
|
||||||
The main file `boot_sect_main.asm` loads a couple strings, calls `print` and hangs. If you understood
|
|
||||||
the previous sections, it's quite straightforward.
|
|
||||||
|
|
||||||
As a last goodie, we will learn how to print newlines. The familiar `'\n'` is
|
|
||||||
actually two bytes, the newline char `0x0A` and a carriage return `0x0D`. Please
|
actually two bytes, the newline char `0x0A` and a carriage return `0x0D`. Please
|
||||||
experiment by removing the carriage return char and see its effect.
|
experiment by removing the carriage return char and see its effect.
|
||||||
|
|
||||||
|
As stated above, `boot_sect_print_hex.asm` allows for printing of bytes.
|
||||||
|
|
||||||
|
The main file `boot_sect_main.asm` loads a couple strings and bytes,
|
||||||
|
calls `print` and `print_hex` and hangs. If you understood
|
||||||
|
the previous sections, it's quite straightforward.
|
||||||
|
@ -4,22 +4,23 @@
|
|||||||
mov bx, HELLO
|
mov bx, HELLO
|
||||||
call print
|
call print
|
||||||
|
|
||||||
; We will get fancy and print a newline
|
call print_nl
|
||||||
; feel free to integrate newline code into "boot_sect_print"
|
|
||||||
mov ah, 0x0e
|
|
||||||
mov al, 0x0A ; newline char
|
|
||||||
int 0x10
|
|
||||||
mov al, 0x0D ; carriage return char
|
|
||||||
int 0x10
|
|
||||||
|
|
||||||
mov bx, GOODBYE
|
mov bx, GOODBYE
|
||||||
call print
|
call print
|
||||||
|
|
||||||
|
call print_nl
|
||||||
|
|
||||||
|
mov dx, 0x1234
|
||||||
|
call print_hex
|
||||||
|
|
||||||
; that's it! we can hang now
|
; that's it! we can hang now
|
||||||
jmp $
|
jmp $
|
||||||
|
|
||||||
; remember to include subroutines below the hang
|
; remember to include subroutines below the hang
|
||||||
%include "boot_sect_print.asm"
|
%include "boot_sect_print.asm"
|
||||||
|
%include "boot_sect_print_hex.asm"
|
||||||
|
|
||||||
|
|
||||||
; data
|
; data
|
||||||
HELLO:
|
HELLO:
|
||||||
|
@ -21,3 +21,17 @@ start:
|
|||||||
done:
|
done:
|
||||||
popa
|
popa
|
||||||
ret
|
ret
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
print_nl:
|
||||||
|
pusha
|
||||||
|
|
||||||
|
mov ah, 0x0e
|
||||||
|
mov al, 0x0a ; newline char
|
||||||
|
int 0x10
|
||||||
|
mov al, 0x0d ; carriage return
|
||||||
|
int 0x10
|
||||||
|
|
||||||
|
popa
|
||||||
|
ret
|
||||||
|
Loading…
Reference in New Issue
Block a user