0

I am writing a small 16-bit OS and I am wondering why input_msg doesn't print the expected output. I am using the BIOS teletype print interrupt and also getting user input and stosb-ing it in input_msg. At least that's the intent.

kernel:

bits 16
org 0x9000

entry:
cld
call clear_screen_widetext
mov si, loaded_kernel
call print_str
jmp handle_enter

hang:
mov ah, 0x10
int 0x16
mov [input_char], al
mov di, input_msg
stosb
mov si, input_char
call print_str
mov al, [input_char]
cmp al, 13
je handle_enter
jmp hang

print_str:
lodsb
mov ah, 0x0E
cmp al, 0
je done
int 0x10
jmp print_str

clear_screen_widetext:
mov ah, 0x0700
int 0x10
ret

handle_enter:
mov si, enter_handle_data
call print_str
mov si, input_msg
mov si, cli_default_text
call print_str
jmp hang

done:
ret

data:
loaded_kernel db 'Loaded Kernel Successfully', 13, 10, 0
input_char db 0, 0
input_msg db 0, 0, 0, 0
enter_handle_data db 10, 0
cli_default_text db '>>>', 0

Any help is appreciated

RAVN Mateus
  • 560
  • 3
  • 13
D_Man
  • 11
  • 2
    This kernel doesn't set ES or DS to match its ORG, and you haven't shown the bootloader so we don't know if that's already happened. (Or whether the bootloader even loads the kernel at the correct address or jumps to it.) So this isn't a [mcve]. Use a debugger (e.g. in Bochs) to single-step your code. – Peter Cordes Sep 07 '21 at 06:56
  • 3
    Also, indent instructions relative to labels, and leave blank lines between blocks (e.g. after a `ret`, or before some loops), so it's readable. This is pretty ugly to read with no comments or formatting. – Peter Cordes Sep 07 '21 at 06:57
  • Thanks and yes the bootloader works bootloader works i can print messages to the screen from this kernel so no issue there – D_Man Sep 07 '21 at 09:38

1 Answers1

0

Why doesn't input_msg print?

Simply because you don't ask it to be printed! Your forgot an extra call print_str here.

mov si, input_msg
                              missing call !!!!!
mov si, cli_default_text
call print_str

But wait, even if you insert this, you won't see the inputted text because your hang input loop, will stosb all characters on top of each other! And because the carriage return (13) is the last one, there's no visual output.

You need to move the mov di, input_msg instruction outside of the hang loop!

And please consult the BIOS api. The BIOS.Teletype function 0Eh and the BIOS.ScrollWindowDown function 07h, both have additional parameters. You are very lucky that all of this works somehow...

Sep Roland
  • 33,889
  • 7
  • 43
  • 76