From 545546ce5eb2602467b02857974767930a74f4c4 Mon Sep 17 00:00:00 2001 From: Carlos Fenollosa Date: Sun, 5 Oct 2014 20:12:33 +0200 Subject: [PATCH] lesson 5 with hex printer --- 05-bootsector-functions-strings/README.md | 21 ++++++++++++++----- .../boot_sect_main.asm | 15 ++++++------- .../boot_sect_print.asm | 14 +++++++++++++ 3 files changed, 38 insertions(+), 12 deletions(-) diff --git a/05-bootsector-functions-strings/README.md b/05-bootsector-functions-strings/README.md index 2039a47..ff5dc79 100644 --- a/05-bootsector-functions-strings/README.md +++ b/05-bootsector-functions-strings/README.md @@ -110,15 +110,26 @@ The syntax is %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! ----- 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. - -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 +It also includes a function to print a newline. The familiar `'\n'` is actually two bytes, the newline char `0x0A` and a carriage return `0x0D`. Please 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. diff --git a/05-bootsector-functions-strings/boot_sect_main.asm b/05-bootsector-functions-strings/boot_sect_main.asm index 8fc261d..fcd4095 100644 --- a/05-bootsector-functions-strings/boot_sect_main.asm +++ b/05-bootsector-functions-strings/boot_sect_main.asm @@ -4,22 +4,23 @@ mov bx, HELLO call print -; We will get fancy and print a newline -; 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 +call print_nl mov bx, GOODBYE call print +call print_nl + +mov dx, 0x1234 +call print_hex + ; that's it! we can hang now jmp $ ; remember to include subroutines below the hang %include "boot_sect_print.asm" +%include "boot_sect_print_hex.asm" + ; data HELLO: diff --git a/05-bootsector-functions-strings/boot_sect_print.asm b/05-bootsector-functions-strings/boot_sect_print.asm index f91e852..b066e0d 100644 --- a/05-bootsector-functions-strings/boot_sect_print.asm +++ b/05-bootsector-functions-strings/boot_sect_print.asm @@ -21,3 +21,17 @@ start: done: popa ret + + + +print_nl: + pusha + + mov ah, 0x0e + mov al, 0x0a ; newline char + int 0x10 + mov al, 0x0d ; carriage return + int 0x10 + + popa + ret