X-Git-Url: http://git.dujemihanovic.xyz/posts?a=blobdiff_plain;f=print.s;h=e1d9bc69d4e1d0cd4341b11213b6ccb8b130d087;hb=b85f8e94af0b9720083f5cd48092ead24e6004c3;hp=ab6eef4c92c9a66441c0abd6c1999ddc61af5bd3;hpb=f9f4f8ebffb463d53ae5a239ddfbe8380f258b8b;p=nameless-os.git diff --git a/print.s b/print.s index ab6eef4..e1d9bc6 100644 --- a/print.s +++ b/print.s @@ -1,12 +1,36 @@ %define CURRENT_ADDR cs:di +; Prints a null terminated string of your choice. +; Arguments: +; CS:DI - pointer to the string you want to print +print: + pusha + mov ah, 0Eh ; teletype print +.write2: + mov al, [CURRENT_ADDR] ; get current char and put it in al + cmp al, 0 ; check if al is null (string terminator) + je .done ; if it is, start a new line + int 10h ; otherwise write the char + inc di ; increment pointer to string + jmp .write2 ; jump back to this section +.done: + mov al, 0Dh ; carriage return + int 10h + mov al, 0Ah ; line feed + int 10h + popa + ret ; return + +; Prints a word (16-bit value) in hex format. +; Arguments: +; DX - word to print print_word: pusha ; push all regs to stack mov di, HEX_OUT+5 ; set destination index to last char in HEX_OUT mov ax, dx ; copy argument to accumulator and al, 00001111b ; extract the low nibble of the low half of the accumulator call .compare ; fill in the string with correct value - dec di ; decrement destination index + dec di ; decrement string pointer mov ax, dx ; copy argument to accumulator and al, 11110000b ; extract high nibble of low half of accumulator shr al, 4 ; shift high nibble to low nibble @@ -20,24 +44,10 @@ print_word: and al, 11110000b shr al, 4 call .compare - jmp .write ; write string - -.write: - popa ; get back our arguments - mov dl, cl ; column - mov dh, ch ; row - pusha ; save registers - mov al, 1 ; update cursor - mov bh, 0 ; page number - mov bl, 00000111b ; colors - mov cx, 6 ; length of string - push cs ; push code segment address - pop es ; pop to extra segment address - mov bp, HEX_OUT ; offset to extra segment of string - mov ah, 13h ; write string - int 10h ; BIOS interrupt + mov di, HEX_OUT + call print ; write string popa - ret ; return + ret .compare: cmp al, 0 ; compare al with 0 @@ -118,4 +128,4 @@ print_word: mov byte [CURRENT_ADDR], 'F' ret -HEX_OUT: db "0x0000" +HEX_OUT: db "0x0000", 0