News:

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

AND

Started by G`HOST, December 16, 2005, 09:22:09 AM

Previous topic - Next topic

G`HOST

Hi,
I have a question regarding AND operator .I know how it works.
But i cant make out how it zeros out the HIWORD in the following instruction:
               AND eax,0ffffh
Thanks for your kind help.

MichaelW

The upper 16 bits of 0FFFFh are all zero, and the lower 16 bits are all one. The AND instruction performs a bitwise AND of the operands. In truth table form, this would be:

a b a AND b
0 0    0
0 1    0
1 0    0
1 1    1

So the upper 16 bits of EAX are set to zero (0 AND 0 = 0, 1 AND 0 = 0), and the lower 16 bits are unchanged (0 AND 1 = 0, 1 AND 1 = 1).


eschew obfuscation

P1

eax holds 32 bits, like FFFFFFFFh, if they were all on.
16 bits looks like       0000FFFFh, if they were on.

So the high part gets zeroed out, while keeping the low part in place.

Regards,  P1  :8)

G`HOST

Thanx MichaelW and P1

"" The upper 16 bits of 0FFFFh are all zero"" Thats the part which was missing from my knowledge.I actually thought that the lower 16 bits carry 0s in 0FFFFh and the upper, 1s.So thats what the "0" before FFFFh means ?

shaldan

0 is needed because without 0 compiler complains: error A2006: undefined symbol : ffffh :]]

P1

Quote from: G`HOST on December 16, 2005, 02:42:14 PM"" The upper 16 bits of 0FFFFh are all zero"" Thats the part which was missing from my knowledge.I actually thought that the lower 16 bits carry 0s in 0FFFFh and the upper, 1s.So thats what the "0" before FFFFh means ?
Don't confuse how it is in a CPU register versus how it is in memory.  Because in memory as a variable the order is reversed.  i.e looking at a memory dump.

Regards,  P1  :8)

MichaelW

G'HOST,

See Integer Constants and Constant Expressions, the paragraph that starts with "Hexadecimal numbers must always start with a decimal digit (0–9)", here:

http://webster.cs.ucr.edu/Page_TechDocs/MASMDoc/ProgrammersGuide/Chap_01.htm

eschew obfuscation