flat assembler
Message board for the users of flat assembler.

Index > Main > and eax, eax?

Author
Thread Post new topic Reply to topic
Plue



Joined: 15 Dec 2005
Posts: 151
Plue
What does
Code:
and eax, eax
jz something    
do?

Does it jump to something if eax is not 0?

_________________
Roses are red
Violets are blue
Some poems rhyme
And some don't.
Post 29 Dec 2005, 21:36
View user's profile Send private message Reply with quote
vid
Verbosity in development


Joined: 05 Sep 2003
Posts: 7105
Location: Slovakia
vid
no. all basic arithmemtic instructions (add, sub, or, xor, and, test, cmp, and one more :] ) set ZF if result is zero and clear it otherwise. "and eax,eax" ANDs every bit of eax with itself, so if eax is nonzero then it must have at least some bit = 1, and "1 and 1 = 1" => result won't be zero => CF will be cleared => jz won't jump.

This is one way how to test if eax is equal to zero, without modifying it
Post 29 Dec 2005, 21:49
View user's profile Send private message Visit poster's website AIM Address MSN Messenger ICQ Number Reply with quote
Plue



Joined: 15 Dec 2005
Posts: 151
Plue
vid wrote:
This is one way how to test if eax is equal to zero, without modifying it
So why does not these two codes do the same?

Works:
Code:
format PE GUI 4.0

include '%fasminc%\win32a.inc'

  start:
        invoke GetAsyncKeyState, 65
        and    eax, eax
        ;cmp    eax, 0
        jnz    exit
        invoke Sleep, 1
        jmp    start
  exit:
        invoke MessageBox, 0, msg, msg,0
        invoke ExitProcess,0

  msg     db "pressed",0

data import
  library kernel,'KERNEL32.DLL',\
          user,'USER32.DLL'

  import kernel,\
         ExitProcess, 'ExitProcess',\
         Sleep, "Sleep"

  import user,\
         MessageBox, "MessageBoxA",\
         GetAsyncKeyState, 'GetAsyncKeyState'
end data    


Does not work:
Code:
format PE GUI 4.0

include '%fasminc%\win32a.inc'

  start:
        invoke GetAsyncKeyState, 65
        ;and    eax, eax
        cmp    eax, 0
        jnz    exit
        invoke Sleep, 1
        jmp    start
  exit:
        invoke MessageBox, 0, msg, msg,0
        invoke ExitProcess,0

  msg     db "pressed",0

data import
  library kernel,'KERNEL32.DLL',\
          user,'USER32.DLL'

  import kernel,\
         ExitProcess, 'ExitProcess',\
         Sleep, "Sleep"

  import user,\
         MessageBox, "MessageBoxA",\
         GetAsyncKeyState, 'GetAsyncKeyState'
end data    


[/code]

_________________
Roses are red
Violets are blue
Some poems rhyme
And some don't.
Post 30 Dec 2005, 11:30
View user's profile Send private message Reply with quote
SDragon



Joined: 13 Sep 2005
Posts: 19
Location: Siberia
SDragon
Quote:
Does not work

It works okay on my machine. Try also test eax, eax; it doesn't write to the register.
Post 31 Dec 2005, 02:49
View user's profile Send private message Reply with quote
Plue



Joined: 15 Dec 2005
Posts: 151
Plue
Strange it works now.
Post 31 Dec 2005, 11:36
View user's profile Send private message Reply with quote
vid
Verbosity in development


Joined: 05 Sep 2003
Posts: 7105
Location: Slovakia
vid
and -> ZF is set if result is zero
cmp -> ZF is set if arguments of equal (eg. if result of subtraction of numbers is zero)
Post 05 Jan 2006, 23:54
View user's profile Send private message Visit poster's website AIM Address MSN Messenger ICQ Number Reply with quote
shism2



Joined: 14 Sep 2005
Posts: 248
shism2
cmp eax, 0
je exit
Post 06 Jan 2006, 00:49
View user's profile Send private message Reply with quote
Matrix



Joined: 04 Sep 2004
Posts: 1171
Location: Overflow
Matrix
hi!
you can use this,
it will work instead of and, smaller in size than cmp...
Code:
or eax,eax
jz .zero
    
Post 06 Jan 2006, 05:09
View user's profile Send private message Visit poster's website Reply with quote
RedGhost



Joined: 18 May 2005
Posts: 443
Location: BC, Canada
RedGhost
Code:
test eax, eax
jz label
    


apparently its better than or, or so i've read in this forum Very Happy

_________________
redghost.ca
Post 06 Jan 2006, 13:41
View user's profile Send private message AIM Address MSN Messenger Reply with quote
shism2



Joined: 14 Sep 2005
Posts: 248
shism2
red ghost is correct Smile

Thats what I've read on this forum too lol
Post 06 Jan 2006, 23:26
View user's profile Send private message 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.

Powered by rwasa.