I am writing a simple OS which prints all stdin (keyboard input) to stdout (the screen). I want to print a welcome string before the input. I'm using NASM since it is readable and easy to use.
I've tried two ways to print the string:
(Assume welcome is defined as db "Welcome to TextEditOS! Type whatever you want below.",0dh,0ah,0dh,0ah,0. Remove the 0 for #2.)
- Using a loop similar to a whileloop. Originally I usedbxinstead ofsisince a few tutorials did it that way, but this answer suggested usingsisincebxis used for the page number and color in TTY mode.
mov si, welcome
mov ah, 0eh
printWelcome:
    cmp [si], byte 0
    je mainLoop
    mov al, [si]
    int 0x10
    inc si
    jmp printWelcome
- Using int 10hwhereah=13h. The code I used is something like this, though I believe I have the original code on my home computer (I'm away right now, will update this question once I get back).
    xor ax, ax
    mov es, ax
    xor bh, bh
    mov bp, welcome
    mov ah, 0x13
    mov bl, 0ah ;this was something else I think
    mov al, 1   ;write mode
    mov cx, 56  ;length
    mov dh, 0   ;x
    mov dl, 0   ;y
    int 0x10
Both of these work just fine in QEMU. However, when I burn the full code onto a USB flash drive and boot it, the first way prints around 1-2 screens of invisible characters before stopping in the middle of the screen, and the other seems to print an @ and nothing else. The rest of my code, which is the keyboard input, works fine both ways.
Here is the full code for my operating system:
[org 0x7c00]
jmp short start
db 90h,90h,"TEXTOS",20h,20h
section .text
start:
; First, let's set up the stack
mov bp, 7c00h
mov sp, bp
; Insert either way I used to print the string below
; end print func
mainLoop:
    mov ah, 0    ; get keyboard input
    int 16h
    mov ah, 0eh  ; print char
    int 10h      ; al already has the char to print
    cmp al, 13   ; is char 0dh?
    je newLine
    cmp al, 8    ; is char 08h?
    je backSpace
    jmp mainLoop ; loop
newLine:
    mov al, 10   ; complete \n with 0ah
    int 10h
    jmp mainLoop
backSpace:
    mov al, 32   ; insert space over last char
    int 10h
    mov al, 8    ; then another backspace to go back
    int 10h
    jmp mainLoop
welcome: ; welcome message
    db "Welcome to TextEditOS! Type whatever you want below.", 0dh, 0ah, 0dh, 0ah, 0
times 510-($-$$) db 0
; Boot signature
dw 0xaa55
Commands used to compile and run:
nasm boot.asm -fbin -oboot.img
qemu-system-x86_64 -drive file=boot.img,format=raw
As said above, I will find the code for #2 and edit this question with it. I will also try to upload some GIFs of what I get on real hardware.
 
    