From bd6235251321e8ba8f91121f7497dd778125d962 Mon Sep 17 00:00:00 2001 From: Robbe Van Herck Date: Fri, 27 Dec 2019 16:17:28 +0100 Subject: [PATCH] Reading and printing strings from hard drives --- .gitignore | 1 + Makefile | 8 ++++ drive.bin | Bin 0 -> 33 bytes main.asm | 113 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 122 insertions(+) create mode 100644 .gitignore create mode 100644 Makefile create mode 100644 drive.bin create mode 100644 main.asm diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..97d14fb --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +boot.bin diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..a675331 --- /dev/null +++ b/Makefile @@ -0,0 +1,8 @@ +compile_and_run: compile run + +compile: + rm -rf boot.bin + nasm -f bin -o boot.bin main.asm + +run: + qemu-system-x86_64 -drive format=raw,file=boot.bin -drive format=raw,file=drive.bin -monitor stdio diff --git a/drive.bin b/drive.bin new file mode 100644 index 0000000000000000000000000000000000000000..ade7f77b2f9b6af83ec28c2394d23a9c70ba570a GIT binary patch literal 33 ocmWH^$ShVUE-A{)OIJwF&rK~>NGr= 10, print as letter +mov al, dl +add al, 0x57 ; 0x57 = (0x61 - 10) +mov ah, 0x0e +int 0x10 + +.puthex_low: +; Print low bits +mov dl, bl +and dl, 0b1111 + +cmp dl, 9 +jg .puthex_low_alpha + +; It's < 10, print as digit +mov al, dl +add al, 0x30 +mov ah, 0x0e +int 0x10 +jmp .puthex_end + +.puthex_low_alpha: +; It's >= 10, print as letter +mov al, dl +add al, 0x57 ; 0x57 = (0x61 - 10) +mov ah, 0x0e +int 0x10 + +.puthex_end: +ret + + + +.start: + +; reset disk system +mov ah, 0x00 +mov dl, 0x81 +int 0x13 + +; print result on error +jnc .reset_disk_no_error +mov bl, ah +call .puthex +.reset_disk_no_error: + +; Read sector 1 into memory +mov ah, 0x02 +mov al, 0x01 ; number of sectors +mov ch, 0x00 ; cylinder number, low 8 bits +mov cl, 0x01 ; cylinder number, high 2 bits + sector number (6 bits) +mov dh, 0x00 ; head number +mov dl, 0x81 ; drive number +mov bx, .data ; data buffer +int 0x13 + +; print result on error +jnc .read_disk_no_error +mov bl, ah +call .puthex +.read_disk_no_error: + +; print string +mov bx, .data +call .puts + +.end: +hlt + +.data: + +times 510 - ($ - $$) db 0 +dw 0xAA55 \ No newline at end of file