From a2eddaeba89be357d74c6758f370374eb75a3247 Mon Sep 17 00:00:00 2001 From: "E. Almqvist" Date: Wed, 13 Jan 2021 11:59:13 +0100 Subject: [PATCH] Updated print sr to work --- src/bootloader.asm | 35 +++++++++++------------------------ src/elib/io.asm | 43 +++++++++++++++++++++++++------------------ 2 files changed, 36 insertions(+), 42 deletions(-) diff --git a/src/bootloader.asm b/src/bootloader.asm index 53ff58a..226de1b 100644 --- a/src/bootloader.asm +++ b/src/bootloader.asm @@ -1,32 +1,19 @@ +[org 0x7c00] ; bootsector + +jmp $ ; inf loop + +;; includes +; EQU %include "equ/BIOS.asm" %include "equ/ASCII.asm" ; eLIB -;; %include "elib/io.asm" - -mov ah, BIOS_MODE_TELETYPE ; enter teletype mode (BIOS) - -mov al, ASCII_LINEBREAK ; linebreak -int BIOS_INT - -;; test db "Welcome to eOS", ASCII_CARRIAGE_RETURN, ASCII_LINEBREAK - -; Print "eOS" -;; mov rcx, test -;; call print - -; ALPHABET PRINT TEST -mov al, 64 ; one less than A since we are printing in a loop and it increments before sys interupt -loop: - ; Print the alphabetic char - inc al ; move to next char - int BIOS_INT ; bios interupt to print it - - cmp al, 90 ; 26 letters in english alphabet (64 + 26) - jl loop ; if al < 64+26: jmp loop - +;%include "elib/io.asm" -jmp $ +;; Data +welcomeString: + db "Welcome to eOS", ASCII_CARRIAGE_RETURN, ASCII_LINEBREAK +; Magic BIOS number times 510-($-$$) db 0 db 0x55, 0xaa diff --git a/src/elib/io.asm b/src/elib/io.asm index 5607c03..fa9eb6d 100644 --- a/src/elib/io.asm +++ b/src/elib/io.asm @@ -1,27 +1,34 @@ ; eLibrary ; Input/Output subroutines -; String structure -; ASCII Offset = 8 bits -; Array of the char bytes, ending with 0 (ASCII_END) +; Subroutine to print a string +print: + pusha ; save current state of registers -eLIB_STR_OFFSET equ 8 ; 8 bits + printLoop: + ; Char check + mov al, [bx] ; load the char + cmp al, ASCII_END ; check if end of string + je return ; if al == ASCII_END then return end | lua is good psuedo-code -print: ; Subroutine to print strings (from stack) - ; Input: RCX, takes pointer to string from stack - pop rcx - ; rcx now holds the starting point (address) + ; BIOS Printing + mov ah, BIOS_MODE_TELETYPE ; enter tty mode + int BIOS_INT ; interupt and print the char (from line 10) - printLoop: - ; Print the char - mov al, [rcx] ; dereference address to get value - cmp al, ASCII_END ; check if ASCII end - je printExit ; if reached the end then return + ; Preperation for next iteration + inc bx ; increment the pointer to get next char + jmp printLoop ; repeat + + return: + popa ; restore all registers + ret ; return to previous location - int BIOS_INT ; system interupt (print string) - add rcx, eLIB_STR_OFFSET ; increase with offset - jmp printLoop ; loop for next char +; Subroutine to print a string on a new line +newline: + db ASCII_CARRIAGE_RETURN, ASCII_LINEBREAK - printExit: - ret +println: + ; Print the newline + mov bx, newline + call print