flat assembler
Message board for the users of flat assembler.

Index > Windows > Help: Which register receives invoke results?

Author
Thread Post new topic Reply to topic
DennisFabian



Joined: 03 Feb 2013
Posts: 2
DennisFabian 03 Feb 2013, 12:36
I am currently new to Assembler, but I've already understood how it generally works.
One question I still have:
why does for example

Code:
invoke  GetModuleHandle,0    


save the handle into eax ?
Why not into a different one ?

I can't find anything about it in the internet. Sad
Everytime I want to use a WINAPI, I can't unterstand how the values get into various registers...

And why does this
Code:
xor eax, eax    

assign the value 0 to eax ?

In other programming language we have to give another variable name like:
Code:
x = a xor a    

so that x becomes false.

Why does
Code:
xor eax, eax    

just makes eax 0. May anyone explain that for me ?

Thanks in advance
Post 03 Feb 2013, 12:36
View user's profile Send private message Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 20344
Location: In your JS exploiting you and your system
revolution 03 Feb 2013, 13:30
1) In the Windows API returned values are always in eax.

2) The XOR reg,same_reg function always produces a zero result regardless of the incoming value of the register. It is commonly used in x86 code because the opcode is shorter than for MOV. But the XOR operation also affects the flags so you need to be aware of that.
Post 03 Feb 2013, 13:30
View user's profile Send private message Visit poster's website Reply with quote
AsmGuru62



Joined: 28 Jan 2004
Posts: 1631
Location: Toronto, Canada
AsmGuru62 03 Feb 2013, 13:41
XOR is a binary operation -- look into Wikipedia to see the logic of it.
But in simple programming terms it would be working like the following:
Code:
XOR DESTINATION, SOURCE
    

If bit in SOURCE is 0 -- DESTINATION bit will not change
If bit in SOURCE is 1 -- DESTINATION bit will invert its value

Example:

Code:
SOURCE:         011011010101010100
DESTINATION:    000100111001000001
                ------------------
RESULT:         011111101100010101
    

If SOURCE is the same as DESTINATION, then all '1' bits in DESTINATION will be inverted
to '0' and that makes whole result to be zero:
Code:
SOURCE:         011011010101010100
DESTINATION:    011011010101010100
                ------------------
RESULT:         000000000000000000
    
Post 03 Feb 2013, 13:41
View user's profile Send private message Send e-mail Reply with quote
f0dder



Joined: 19 Feb 2004
Posts: 3175
Location: Denmark
f0dder 03 Feb 2013, 15:07
DennisFabian wrote:
why does for example

Code:
invoke  GetModuleHandle,0    


save the handle into eax ?
Why not into a different one ?

I can't find anything about it in the internet. Sad

It's called "calling convention" - being a convention, it's the same across the entire Win32 API.

DennisFabian wrote:
In other programming language we have to give another variable name like:
Code:
x = a xor a    

so that x becomes false.

x86 instructions tend to have hardcoded destination; other achitectures might define the instruction as "XOR destination, operand1, operand2", but for x86 doesn't. With intel assembly syntax, the first operand is usually re-used for destination (but then there's stuff like MUL and DIV with fixed output registers). I suggest you download The Manuals and browse through - they are massive, though. There's also a bit here that's slightly more digestible, and the book project at the asmcommunity (haven't really looked much at it, and it seems page ordering is alphabetized instead of logical progression). I also recall FASM.PDF being a decent read.

_________________
Image - carpe noctem
Post 03 Feb 2013, 15:07
View user's profile Send private message Visit poster's website Reply with quote
DennisFabian



Joined: 03 Feb 2013
Posts: 2
DennisFabian 03 Feb 2013, 16:28
Thanks for all the replies!!
Haha. I know what xor means and what it does! I just wanted to know why the result of the operation gets saved in eax too.
Thank you for all the answers! You helped me alot!!
Post 03 Feb 2013, 16:28
View user's profile Send private message Reply with quote
AsmGuru62



Joined: 28 Jan 2004
Posts: 1631
Location: Toronto, Canada
AsmGuru62 03 Feb 2013, 16:34
The 1st operand in ASM instruction is USUALLY the one that is a destination,
the one that will be modified as a result of the instruction.
Post 03 Feb 2013, 16:34
View user's profile Send private message Send e-mail Reply with quote
Display posts from previous:
Post new topic Reply to topic

Jump to:  


< Last Thread | Next Thread >
Forum Rules:
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Copyright © 1999-2024, Tomasz Grysztar. Also on GitHub, YouTube.

Website powered by rwasa.