Printing Strings with BIOS

Question about which tools to use, bugs, the best way to implement a function, etc should go here. Don't forget to see if your question is answered in the wiki first! When in doubt post here.
Post Reply
Jubbens

Printing Strings with BIOS

Post by Jubbens »

I know this is likely asked alot, but I'm kinda stuck.

I wrote my bootloader, and a simple kernel. I guess the next step is "Hello World". Since I'm still in real mode, I'd like to use int 10 AH=0x0E

Code: Select all

; print - print a string
print:
.loop
<----- ROFFLEZ WTF ----->
mov ah,0x0E
int 0x10
<----- If not end of string ----->
jz .loop
ret

db "Hello World"
I need help with this routine. I suppose there's some example kernel that has this routine? I don't want to just copy it though....don't learn anything that way.

Thanks.
AR

Re:Printing Strings with BIOS

Post by AR »

This is a function I wrote when I was using my own bootloader:

Code: Select all

;PARAMETERS: char* Txt{SI}
;ALTERED REGISTERS: SI
PrintChars:
push ax
push bx

;Show character using Teletype BIOS function
mov ah,0Eh    ; This number is the number of the function in the BIOS to run.
mov bh,0h    ; Page number (???)
mov bl,07h    ; Text attribute (Background and Foreground colour) 07=Grey on Black

.PrintNextChar:
lodsb ;Load next byte from pointer in SI into AL then advance SI by 1

or al, al
JZ .Return

int 10h       ; Call the BIOS video interrupt.

jmp .PrintNextChar  ; Put it into a coninuous loop to load characters and show them

.Return:
pop bx ;Restore registers and return
pop ax
ret
You should be able to work this out reasonably easily, but an example of its use is:

Code: Select all

String1: db "Hello World",0

MOV SI, String1
CALL PrintChars
Jubbens

Re:Printing Strings with BIOS

Post by Jubbens »

Why are ax and bx pushed and popped? How are they altered in this process?
AR

Re:Printing Strings with BIOS

Post by AR »

I like implementing my functions so that they don't alter the core registers [AX,BX,CX,DX] unless it's returning a value since it makes it easier to recycle code.

I think how they're altered should be immediately obvious via the MOV operations.
Post Reply