Page 1 of 2

Printing new line on boot

Posted: Tue Sep 19, 2017 4:35 am
by mondelob
I tested a simple program on ASM that receives the user input and echoes back the message using the BIOS interrupt calls.
All works fine in QEMU, but when I test this loader on real hardware doesn't shows the newline.
The function that shows the newline is the following:

Code: Select all

newline:              ; Adds a new line
    mov al, 13        ; Set AL to the CR character
    call printc       ; Show the character
    mov al, 10        ; Set AL to the vertical tab character
    call printc       ; Show the character
    ret

(printc prints the caracter on the AL register)
Anyone knows why it doesn't works on real hardware?
Thanks! :)

Re: Printing new line on boot

Posted: Tue Sep 19, 2017 5:34 am
by Octocontrabass
My guess is something along these lines.

I can't be more specific without seeing more code.

Re: Printing new line on boot

Posted: Tue Sep 19, 2017 6:06 am
by mondelob
Thanks! I will search for an error there. The full code is in https://github.com/mondelob/OrigamiSystem/blob/master/One/Bootloader/boot.asm
Could be that there's no 16 Bits statement?

Re: Printing new line on boot

Posted: Tue Sep 19, 2017 6:37 am
by Octocontrabass
NASM and YASM default to generating 16-bit code when the output format is flat binary. You don't need "bits 16" but it's a good idea to include it for clarity.

Are you sure you're calling this BIOS function correctly?

Re: Printing new line on boot

Posted: Tue Sep 19, 2017 7:13 am
by iansjack
Are you sure that you are handling the CR/LF and TAB characters correctly, rather than just trying to echo the character to the screen?

Re: Printing new line on boot

Posted: Tue Sep 19, 2017 7:31 am
by onlyonemac
iansjack wrote:Are you sure that you are handling the CR/LF and TAB characters correctly, rather than just trying to echo the character to the screen?
It looks like they are. They're using a BIOS function that's supposed to interpret these characters.

To OP: I'm not sure what's wrong with your code as it looks OK to me. Please be aware that "vertical tab" and "line feed" are not the same thing.

Re: Printing new line on boot

Posted: Tue Sep 19, 2017 7:42 am
by mondelob
Actually I'm first showing a CR character (13) and after a LF character (10), those are the supposed to show a new line.
Maybe it's a BIOS problem? :O
Sorry for my questions, I'm a bit new with Assembly and BIOS programming

Re: Printing new line on boot

Posted: Tue Sep 19, 2017 8:37 am
by AJ
Please don't use coloured text - some of us are using dark themes where your posts are only visible by highlighting the text.

Cheers,
Adam

Re: Printing new line on boot

Posted: Tue Sep 19, 2017 9:42 am
by Octocontrabass
Taking another look at your code, I see that you're using LODSB without CLD. You need to make sure the direction flag is set correctly before you use any string instructions.

Did you look at this documentation yet? Here's a hint: which registers must you set before using that function?

Re: Printing new line on boot

Posted: Tue Sep 19, 2017 2:34 pm
by onlyonemac
mondelob wrote:Maybe it's a BIOS problem? :O
Try it on another computer. This will rule out any BIOS bugs specific to your computer.

Re: Printing new line on boot

Posted: Thu Sep 21, 2017 12:54 pm
by MichaelPetch
Just thinking out loud.

I'm curious if you are booting this on real hardware using USB with Floppy emulation. I only ask because if this is the scenario then it is possible that the BIOS is overwriting some of the code and data in your program when it updates the BIOS Parameter Block (BPB). If this is the type of environment you are running in, I'd create a BPB just to allocate the space that may be overwritten by the BIOS.

Re: Printing new line on boot

Posted: Mon Oct 02, 2017 3:21 am
by mondelob
onlyonemac wrote:Try it on another computer. This will rule out any BIOS bugs specific to your computer.

Tested on other machine and worked correctly.. still didn't know why on my BIOS doesn't show it

Re: Printing new line on boot

Posted: Mon Oct 02, 2017 10:44 am
by onlyonemac
mondelob wrote:
onlyonemac wrote:Try it on another computer. This will rule out any BIOS bugs specific to your computer.

Tested on other machine and worked correctly.. still didn't know why on my BIOS doesn't show it
Try pushing everything to the stack before calling the BIOS function and then popping it afterwards. If this works then I'm guessing that the BIOS function is corrupting a register that you aren't expecting it to. Check the documentation for the function that you're using and see what registers are supposed to be preserved, if you're expecting it to preserve registers that it isn't supposed to preserve then it's possible that it might work on some BIOSes that happen to preserve those registers but not on others that don't, otherwise your BIOS is evidently corrupting a register that it's supposed to preserve.

Re: Printing new line on boot

Posted: Mon Oct 02, 2017 11:51 am
by MichaelPetch
I'll ask again. Are you testing this on real hardware using a USB device as a boot device?

Re: Printing new line on boot

Posted: Mon Oct 02, 2017 12:02 pm
by mondelob
MichaelPetch wrote:I'll ask again. Are you testing this on real hardware using a USB device as a boot device?

Yes

onlyonemac wrote:Try pushing everything to the stack before calling the BIOS function and then popping it afterwards. If this works then I'm guessing that the BIOS function is corrupting a register that you aren't expecting it to. Check the documentation for the function that you're using and see what registers are supposed to be preserved, if you're expecting it to preserve registers that it isn't supposed to preserve then it's possible that it might work on some BIOSes that happen to preserve those registers but not on others that don't, otherwise your BIOS is evidently corrupting a register that it's supposed to preserve.

Im a bit new in ASM, you push every register before calling the function, and then once I entered in for example printc or newline; pop all the registers?