Page 1 of 1
Odd Assembly Bug
Posted: Mon Oct 26, 2009 10:44 pm
by Langle
Ok, I am creating a simple bootloader, and I found a weird bug. The buggy code:
Code: Select all
ReadDiskCHS:
push ax
push bx
xor bl,bl
mov al,'1'
Call PrintChar
pop bx
pop ax
mov AH,2
int 13h ;Call BIOS
push ax
push bx
xor bl,bl
mov al,'2'
Call PrintChar
pop bx
pop ax
jc ReadDiskCHS ;If there was an error restart
ret ;Else return
When I use the code like this, It doesn't hang, but when i take out the line
Code: Select all
push ax
push bx
xor bl,bl
mov al,'1'
Call PrintChar
pop bx
pop ax
It just stops a int 13H
Here is the code for PrintChar:
Code: Select all
PrintChar:
xor bh,bh
mov ah,0eh
int 10h
ret
Thanks for any help, The numbers were originally paced there for simple debugging purposes
Re: Odd Assembly Bug
Posted: Tue Oct 27, 2009 2:19 am
by 01000101
You're not filling in all of the parameters for Int 0x13 AH=2. For instance, do you know what CX, DX, and BX are... are even what ES is? A description of what is required of this particular BIOS interrupt can be found
here.
Re: Odd Assembly Bug
Posted: Tue Oct 27, 2009 3:02 am
by xenos
This changes the carry flag, so if you insert this piece of code, the conditional jump will behave differently. You should also pushf / popf if you want to preserve the flag status and perform a conditional jump that relies on the previous flag state.
Re: Odd Assembly Bug
Posted: Tue Oct 27, 2009 4:15 pm
by Langle
XenOS wrote:
This changes the carry flag, so if you insert this piece of code, the conditional jump will behave differently. You should also pushf / popf if you want to preserve the flag status and perform a conditional jump that relies on the previous flag state.
Forgot about that, the code other registers is before this, the code i posted is a procedure.
Re: Odd Assembly Bug
Posted: Wed Oct 28, 2009 12:14 am
by tantrikwizard
You don't provide enough information to know what is going on at run-time. int 0x13 function 0x02 requires distinct values in certain registers before issuing the command. You don't supply that info here so there's no way to know what is going on. Read up on the following tutorials:
http://wiki.osdev.org/Bootloader
http://wiki.osdev.org/Rolling_Your_Own_Bootloader
You would also benefit by learning assembler and BIOS calls:
http://wiki.osdev.org/ATA_in_x86_RealMode_(BIOS)
When all else fails, read a book or two from the suggested readings:
http://forum.osdev.org/viewtopic.php?f=1&t=6989