flat assembler
Message board for the users of flat assembler.

Index > Windows > Insight into register-values

Author
Thread Post new topic Reply to topic
kasake36



Joined: 28 Mar 2006
Posts: 68
kasake36
Hello! I'm trying to understand the FASM TrayIcon example, but got stuck at the beginning-code:
Code:
1: invoke       GetModuleHandle,0
2: mov  [hInstance],eax
; initialise main window
3: mov  [wc.hInstance],eax
4: xor  eax,eax
5: mov  [wc.cbSize],sizeof.WNDCLASSEX
6: mov  [wc.style],eax
    

Line 1 to 3 are clear to me, but then the magic begins. eax is XORed with itself, and later eax is shifted into wc.style....? This has to mean that eax holds the same value every time after GetModuleHandle was invoked? Otherwise i can't explain that the programmer shifted eax into wc.style - if he doesn't know what it holds. But how can i explore what the registers hold at specific points? And why does GetModuleHandle always returns the same Instance-Handle? Thank you.
Post 30 Mar 2006, 14:44
View user's profile Send private message Reply with quote
RedGhost



Joined: 18 May 2005
Posts: 443
Location: BC, Canada
RedGhost
hey, after the call to GetModuleHandle eax holds the handle since eax is used for return values, if you send 0 to GetModuleHandle it returns the current module, or you can specify the name for a specific handle (see the MSDN)

about xor:

"Each bit of the result is 1 if the corresponding bits of the operands are different; each bit is 0 if the corresponding bits are the same."

since its xor eax, eax, each bit would be the same (obviously) so all 32bits get set to 0, its a trick to make eax 0 without using an immediate or memory and its generally faster

so
Code:
xor eax, eax
mov  [wc.style],eax
    


is the same as
Code:
mov  [wc.style],0
    


i hope that clears it up

_________________
redghost.ca


Last edited by RedGhost on 30 Mar 2006, 15:08; edited 1 time in total
Post 30 Mar 2006, 15:06
View user's profile Send private message AIM Address MSN Messenger Reply with quote
vid
Verbosity in development


Joined: 05 Sep 2003
Posts: 7105
Location: Slovakia
vid
when you xor something with itself then it becomes zero. so it is just moving zero to wc.style. about xoring: 1 xor 1 = 0, 0 xor 0 = 0, so when you xor something with itself it always becomes 0.
Post 30 Mar 2006, 15:07
View user's profile Send private message Visit poster's website AIM Address MSN Messenger ICQ Number Reply with quote
RedGhost



Joined: 18 May 2005
Posts: 443
Location: BC, Canada
RedGhost
vid wrote:
when you xor something with itself then it becomes zero. so it is just moving zero to wc.style. about xoring: 1 xor 1 = 0, 0 xor 0 = 0, so when you xor something with itself it always becomes 0.


i guess you were writing yours just as i posted my reply :p

_________________
redghost.ca
Post 30 Mar 2006, 15:09
View user's profile Send private message AIM Address MSN Messenger Reply with quote
kasake36



Joined: 28 Mar 2006
Posts: 68
kasake36
Ah, that's clear now! Thx for the help!
Post 30 Mar 2006, 15:12
View user's profile Send private message Reply with quote
vid
Verbosity in development


Joined: 05 Sep 2003
Posts: 7105
Location: Slovakia
vid
redghost: yup...
Post 30 Mar 2006, 15:38
View user's profile Send private message Visit poster's website AIM Address MSN Messenger ICQ Number 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-2020, Tomasz Grysztar. Also on GitHub, YouTube, Twitter.

Website powered by rwasa.