Returning...?

Posts 17 of 7 · Page 1 of 1
Returning...?
Hey. Got a question for you guys. Now i'm not sure if the syntax is correct but i'm sure you'll understand what i'm trying to say.

If I do something like this:

Code:
.data
wind db "Minesweeper"
.code
start:
PUSH addr wind
PUSH 0
call FindWindow
Now if we search the FindWindow function in MSDN we can clearly see it's return type is HWND. My question is, where exactly did that return value go to?

One more question. Is there a way to intercept the returning of this value before it is actually returned? For example, if I have a function that adds 2 numbers then returns the result. Before it returns the result is there a way I can edit the value and then return it?

Thanks.
1) return values are stored in EAX (or RAX on 64 bit)
2) That depends - is it your own function? Really all you're gonna end up with is some code that'll be something like this

Code:
//Let's say ebx and ecx hold our 2 numbers
mov eax, ebx
add eax,ecx
ret
So if you want to change the value then you'd have to either change the code of that function before it hits the 'ret' statement, or modify EAX in the calling code before it does anything with it.
Code:
call AddNumbers //let's say it returned 10
//eax now holds return value 10 so if you added:

mov eax,5 // now the program thinks AddNumbers returned 5

//Do Something with eax (which would be 5 instead of 10)
So no matter what the return type is, it'll always go to EAX register? Or would different types be directed at different registers?
Standard convention is to always use EAX - so if it's a struct/class or whatever, then eax will obviously hold a pointer to that struct
Thanks B1ackAnge1.

And I'm assuming you can use CMP instruction in place of if and else?
Something like:

Code:
call Addnumber
cmp eax,5
JE somewhere
If whatever it returned is equal to 5 it jumps somewhere. Correct me if i'm wrong. And sorry for these noob-ish questions i'm really new to assembly.
Exactly - though if you use masm32 you could actually use a '.if' statement (but that's not nearly as fun)

No Worries about the questions Good to see someone else taking an interest in Assembly
I am using MASM and yeah I know about that .if, If I wanted to make things easier I wouldn't try to learn assembly. I'm trying to understand what the computer see's. I'm assuming that makes me understand in general how most other languages work.

Anyways, thanks B1ackAnge1
Very helpful information.
Posts 17 of 7 · Page 1 of 1

Post a Reply

Similar Threads

Tags for this Thread

None

Need help?