flat assembler
Message board for the users of flat assembler.
![]() |
Author |
|
vid 29 Dec 2005, 21:49
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 |
|||
![]() |
|
Plue 30 Dec 2005, 11:30
vid wrote: This is one way how to test if eax is equal to zero, without modifying it 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. |
|||
![]() |
|
SDragon 31 Dec 2005, 02:49
Quote: Does not work It works okay on my machine. Try also test eax, eax; it doesn't write to the register. |
|||
![]() |
|
Plue 31 Dec 2005, 11:36
Strange it works now.
|
|||
![]() |
|
vid 05 Jan 2006, 23:54
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) |
|||
![]() |
|
shism2 06 Jan 2006, 00:49
cmp eax, 0
je exit |
|||
![]() |
|
Matrix 06 Jan 2006, 05:09
hi!
you can use this, it will work instead of and, smaller in size than cmp... Code:
or eax,eax
jz .zero
|
|||
![]() |
|
RedGhost 06 Jan 2006, 13:41
Code:
test eax, eax
jz label
apparently its better than or, or so i've read in this forum ![]() _________________ redghost.ca |
|||
![]() |
|
shism2 06 Jan 2006, 23:26
red ghost is correct
![]() Thats what I've read on this forum too lol |
|||
![]() |
|
< Last Thread | Next Thread > |
Forum Rules:
|
Copyright © 1999-2025, Tomasz Grysztar. Also on GitHub, YouTube.
Website powered by rwasa.