News:

MASM32 SDK Description, downloads and other helpful links
MASM32.com New Forum Link
masmforum WebSite

When you thought you knew something well....

Started by xandaz, November 27, 2011, 03:55:14 PM

Previous topic - Next topic

xandaz

    Obviously by this time i should have had this well learned but it appears that i don't. I'm reffering to the way flags changes due to logical opperations.
    For instance:

_test  dd   11111111111111111111111111111100b

.code
       test    _test,100b


i was thinking that it would set CF or Clear ZF if the immidiate opperand were to be 0 but it doesn't. Can someone explain how this works. And what is the parity flag for?
thanks

qWord

Which flags and how they are affected can be read in the documentation (AMD, Intel).
TEST is the same as AND, except, that the destination operator is not modified - a barrow can not occur, thus the CF flags is allways set to 0 (the same applies to OR and XOR).
The parity flag is set, when the low order byte of the result holds an even number of '1'-bits:
e.g.:
AL = 011y -> PF=1
AL = 001y -> PF=0

In your example the result would be  100y, thus ZF, PF and SF are cleard.
FPU in a trice: SmplMath
It's that simple!

zemtex

The parity flag is set if the number of set bits is even in the least significant byte of the result.

I have been puzzling with lego bricks all my life. I know how to do this. When Peter, at age 6 is competing with me, I find it extremely neccessary to show him that I can puzzle bricks better than him, because he is so damn talented that all that is called rational has gone haywire.

dedndave

the logical instructions, AND, OR, XOR, TEST, always clear the carry flag
they already covered PF
usually, the only flag of interest with TEST is the ZF   :P

Farabi

If you want to test spesific bit, I used to use "BT" instruction, it is lot simpler, and maybe tinier, dont know about the speed.


BT cx,1 ; Test bit 1 for set, if it is carry it is set, if not, it is not setted. Dead simple
Those who had universe knowledges can control the world by a micro processor.
http://www.wix.com/farabio/firstpage

"Etos siperi elegi"

xandaz

    Thanks guys.... i feel kinda stupid for the post but i'm thankful for the intel.
    BT? never heard of it. Oh i see it now. Damn i'm way behind with the oppcodes. Got to get my stuff together.


Farabi

Those who had universe knowledges can control the world by a micro processor.
http://www.wix.com/farabio/firstpage

"Etos siperi elegi"

xandaz

    yeah... i've been having a hard time to understand what seems too obvious. The opcode ref says of 'BT' :The destination bit indexed by the source value is copied into the Carry Flag.
   But then i have this code:
or eax,1
test eax,1   ; no zero flag and it's alright
bt eax,1      ; CF keeps unset

why didnt CF set? The indexed bit0 isnt copied into CF and bit0 of eax==1... wtf
and then this:

or eax,1
bt eax,0  ; CF is set

why is this? bit0 of eax==0 and 0 AND 1 ==0 wtf?
Can someone explain this?

xandaz

    Alright... nevermind... i just saw a post by donkey explaining it. So the source allows a 256 bit zero based indexing possibilities.
    Sorry... it was that obvious. I should take care of my chi or something... loosing attention.
    Thanks and later