Hi assembly gurus :)

I'm new to this board, this is my first post. I've lurking around here since February though, but now I finally had to ask a question. I'm just learning assembly, I'm still stuck in the basics but I feel I'm doing well, I'm very familiar with JavaScript and Perl. I've tried some C++ too. I understand pretty well how all basic functions work, like a window. That you need to register a window class, then create the window, and enter a loop that gets messages from the OS whenever something is done to the window. Assembly feels like a good language for me.

Anyway, I'm still a complete newbie and I would like to ask about debugging my code. I made a program that simply just opens a window, but the program didn't work. I didn't get any error message when assembling it, not even one of those cryptic error messages from Windows when running it. I compared my code to the code from a tutorial, and was lost... finally, I found what was wrong. I was missing a ret from the WndProc.

I would like to know, is there any program for helping me find such errors? I once saw a screenshot from some program where the assembly code was at left, and a status window to right. The status window showed whenever a register was updated and stuff, I think such a program would help me find my stupid errors. So what would you recommend?

Posted on 2004-05-13 11:36:09 by Justin Case
Get familiar with a debugger. Learn how to set break points and inspect the registers and memory when the code breaks at the breakpoint learn the single step so that that you can watch the registers and memory values change as you step into the code.

Debugging is an art, one that requires patience and experience.]

A debugger that I would recommend is ollydbg. Some prefer softice, but it is too expensive for me.
Posted on 2004-05-13 11:57:40 by roticv
I guess each and everyone of us already had the missing ret problem. :) Once you scratched your head for half an hour before finding it - it hardly ever happens again.

Also, for the missing ret problem, may I suggest Ketil's RadAsm which inserts a ret automatically in each proc when you define a proc, that's a way to keep it from happening.

Also, this won't happen as you start programming more and get into the habit of compiling after each proc. A quick launch every once in a while (after every finished proc) tells you if stuff is working or not. Pretty easy to locate a missing ret then.
Posted on 2004-05-13 11:59:06 by JimmyClif
Thanks for your replies! :)
Yes, I realize that I need to get more into the coding, I'm very new to assembly. <boast>I tend to find typical and even more complicated JavaScript errors easily.</boast> :D

I just downloaded ollydbg and will try it, I'll tell you later on how I liked it.

/added: I'll also download RadAsm at some point :)
Posted on 2004-05-13 12:10:43 by Justin Case
Justin Case,

Ollydbg is a free debugging tool available from:

Posted on 2004-05-13 12:54:29 by Vortex
yes... I found it on google already... I just said in my previous post that I downloaded it :)

It looks a bit confusing to me... but I will study it. While I'm at it, may I ask another question? In a part of the window code, I see this:
xor eax, eax

What exactly does that do?
Posted on 2004-05-13 13:09:34 by Justin Case
It zero's out eax.. it's equal to mov eax, 0
Posted on 2004-05-13 13:15:28 by JimmyClif
Hi Justin Case,

xor stands for eXclusive OR which means that if two arguments are TRUE / FALSE, the result is FALSE , otherwise the result is TRUE.

The classical OR operator does:

1 or 1 = 1
1 or 0 = 1
0 or 0 = 0


1 xor 1 = 0
1 xor 0 = 1
0 xor 0 = 0

So, eax XORed with eax

xor eax,eax

gives 0.

This is the optimized way of setting eax to 0.
Posted on 2004-05-13 13:20:39 by Vortex
Ok, thanks for the information, Vortex and JimmyClif. But why do you have to use the xor then, what does "optimized way" mean? Why not the mov eax, 0?
Posted on 2004-05-13 13:43:10 by Justin Case
Because it's 2 bytes as opposed to 5 bytes.
Posted on 2004-05-13 14:28:25 by Sephiroth3

Thanks, I see now!
Posted on 2004-05-13 15:26:38 by Justin Case
One important detail on using XOR reg for zeroing a register. It does affect several of the flags in the flag register. You may even want to use that simply to set the Z(ero) flag for whatever reason if you don't need that register. However, if you ever have to zero a register before making a conditional jump (or using some of the flags for any other purpose), you must then use the MOV reg,0 instruction which does not affect any of the flags in the flag register.

Posted on 2004-05-13 22:41:39 by Raymond
It breaks dependency IIRC
Posted on 2004-05-14 05:00:39 by roticv
This is off topic... but nice to see other finnish people here!
Posted on 2004-05-14 16:18:07 by SamiP
Moi Sami :)

I know how it feels like, there are some large forums where I'm the only (active) Finnish member, when I meet another Finn it feels like finding an ice cream bar in the middle of a desert :grin:
Posted on 2004-05-14 16:39:09 by Justin Case

<boast>I tend to find typical and even more complicated JavaScript errors easily.</boast> :D
With practice you will be able to do the same with x86. IMHO, we all have to bump our heads to get sore enough to remember. :) I'll write a complex algorithm without any debugging and then debug the whole thing in one go -- bouncing back and forth from RadASM and OllyDbg correcting all the errors as I see them. When I get really tired I'll spend a long time on a silly error -- writing code to narrow down the possiblities (including the bug in that code too, of course!) and tracing thorugh the code several dozen times until I am certain of liquid mush in my skull and drift off to sleep...

Posted on 2004-05-14 16:58:09 by bitRAKE
hehehe.. occasionally I thought it was easier just to rewrite the part that was buggy all over again :)
Posted on 2004-05-14 17:38:50 by JimmyClif