Odd Assembly Bug

Programming, for all ages and all languages.
Post Reply
Langle
Posts: 2
Joined: Mon Oct 26, 2009 10:36 pm

Odd Assembly Bug

Post 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
User avatar
01000101
Member
Member
Posts: 1599
Joined: Fri Jun 22, 2007 12:47 pm
Contact:

Re: Odd Assembly Bug

Post 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.
User avatar
xenos
Member
Member
Posts: 1118
Joined: Thu Aug 11, 2005 11:00 pm
Libera.chat IRC: xenos1984
Location: Tartu, Estonia
Contact:

Re: Odd Assembly Bug

Post by xenos »

Code: Select all

xor bl,bl
...
xor bh,bh
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.
Programmers' Hardware Database // GitHub user: xenos1984; OS project: NOS
Langle
Posts: 2
Joined: Mon Oct 26, 2009 10:36 pm

Re: Odd Assembly Bug

Post 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.
tantrikwizard
Member
Member
Posts: 153
Joined: Sun Jan 07, 2007 9:40 am
Contact:

Re: Odd Assembly Bug

Post 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
Post Reply