Page 1 of 1

how to easily debug you code!

Posted: Fri Aug 09, 2002 6:57 pm
by beyondsociety
I was looking at the newsgroups link on the www.osdev.com website and summbled on to a sure fire way to easily debug your code. I though alot of people might want to know how to do this.

After every one or more lines of code, add a message to the code.

If you have ten messages, them you have ten numbers.

Put all ten messages in the code and then run it.

If you have ten messages and you only see 5 on the screen, then you know theres a problem between line 5 and the rest of your messages.

example:

[org 0x7c00]

start:

xor ax,ax
mov ax,cs

mov si,one
call print

mov es,ax

cli
mov ax,0
mov ss,ax
mov sp,0xffff
sti

mov si,two
call print

print:

lodsb
or al,al
jz return
int 10h
jmp print

return:

ret

one db '1',13,10,0
two db '2',13,10,0

times 510-($-$$) db 0
dw 0xAA55

If it displays only one out of the two messages, then you know you have a problem with message two area.

Got it!

Re:how to easily debug you code!

Posted: Fri Aug 09, 2002 10:00 pm
by K.J.
You can also use Bochs and use the hlt instruction(Bochs will report if it comes across the hlt inscruction). Just keep moving the hlt instruction down(actually, use, cli and hlt) until Bochs doens't report it. Right before the hlt is the problem:
[tt]
...
int 0xB8
cli
hlt
...
[/tt]

Of course, this method only works in Bochs.

K.J.

Re:how to easily debug you code!

Posted: Sat Aug 10, 2002 6:22 am
by frank
I always had another way of debugging...
put everything in comment except for the small begining code..
if that works uncomment another part... and another part... and so on :)