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.
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:
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! :)
Last edited by mondelob on Tue Sep 19, 2017 8:51 am, edited 1 time in total.
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.
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.
When you start writing an OS you do the minimum possible to get the x86 processor in a usable state, then you try to get as far away from it as possible.
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
Last edited by mondelob on Tue Sep 19, 2017 8:50 am, edited 1 time in total.
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?
Try it on another computer. This will rule out any BIOS bugs specific to your computer.
When you start writing an OS you do the minimum possible to get the x86 processor in a usable state, then you try to get as far away from it as possible.
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.
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.
When you start writing an OS you do the minimum possible to get the x86 processor in a usable state, then you try to get as far away from it as possible.
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?