News:

Masm32 SDK description, downloads and other helpful links
Message to All Guests

Main Menu

example to test NOT&NEG

Started by xiahan, June 14, 2012, 06:11:46 PM

Previous topic - Next topic

xiahan

the Exe should be ran under CONSOLE subsystem

the NEG is just plus one after the operand has been NOT,
cause its arithmetic instruction
i mean take WORD for example

10000 H- 0F??FH

qWord

What is your question?

neg(x) = (NOT x) + 1

e.g. WORD values
neg(1) = (0xfffe) + 1 = 0xffff = -1
neg(0xffff) = (0) + 1 = 1
MREAL macros - when you need floating point arithmetic while assembling!

dedndave

generally speaking, NOT is regarded as a logical function, while NEG is a math function
that may seem like splitting hairs   :P

but - the devil is in the details - in this case, the flags
NOT doesn't alter any flags, while NEG does - most notably, the sign, zero, and carry flags

that actually makes NOT unusual, even as a logical instruction
most logical instructions clear the carry flag and set the sign and zero flags according to results
i have had occassions where i wished it did set the flags, too   :(

FORTRANS

Hi,

   NEG is twos complement negation, NOT is either
a ones complement negation or a logical bitwise AND.

Quote
NOT doesn't alter any flags, while NEG does - most notably, the sign, zero, and carry flags

that actually makes NOT unusual, even as a logical instruction
most logical instructions clear the carry flag and set the sign and zero flags according to results
i have had occassions where i wished it did set the flags, too

   Yeah, odd.  And note, that TEST is described as a
non-destructive AND, and it sets the flags.  So you
could do a TEST - AND or an AND - TEST sequence
if needed.  (Not that I ever remember to do that the
first time around...)

Regards,

Steve N.

xiahan

Quote from: qWord on June 14, 2012, 06:53:20 PM
What is your question?


no questions at all, just make a little program to do some demonstration :biggrin:

although its simple, i think someone my need this

xiahan

Hi,Dave,FORTRANS and qWord

for the two's complementation ,
if gives 0
then NEG(0)=[NOT(0)=FFFFFFFF] + 1 =0
also 100000000 - 0 = 100000000 or just 00000000
in MASM , we can use CARRY? to test whether CARRY FLAG is set
but in GoAsm, what should i use?
and for other Flags test,is there any OPCAODE?

dedndave

there are branch instructions that branch or do not branch, based on the state of specific flags

if you NEG a value that was 0, it remains 0
the carry flag will be cleared and the zero flag will be set
for all other values, the carry flag will be set and the zero flag will be cleared

if you NEG a "max negative" value (80h for bytes, 8000h for words, or 80000000h for dwords)
the value remains unchanged and the overflow flag is set
for all other values, the overflow flag is cleared

the sign flag always reflects the sign of the result

you can use any of the conditional branch instructions following NEG
****************************************************************
Equality Branches (Used for Signed or Unsigned Comparisons)
----------------------------------------------------------------
Instruction  Description               Condition       Aliases
----------------------------------------------------------------
JZ           Jump if equal             ZF=1            JE
JNZ          Jump if not equal         ZF=0            JNE
****************************************************************

****************************************************************
Unsigned Branches
----------------------------------------------------------------
Instruction  Description               Condition       Aliases
----------------------------------------------------------------
JA           Jump if above             CF=0 and ZF=0   JNBE
JAE          Jump if above or equal    CF=0            JNC JNB
JB           Jump if below             CF=1            JC JNAE
JBE          Jump if below or equal    CF=1 or ZF=1    JNA
****************************************************************

****************************************************************
Signed Branches
----------------------------------------------------------------
Instruction  Description               Condition       Aliases
----------------------------------------------------------------
JG           Jump if greater           SF=OF or ZF=0   JNLE
JGE          Jump if greater or equal  SF=OF           JNL
JL           Jump if less              SF<>OF          JNGE
JLE          Jump if less or equal     SF<>OF or ZF=1  JNG
JO           Jump if overflow          OF=1
JNO          Jump if no overflow       OF=0
JS           Jump if sign              SF=1
JNS          Jump if no sign           SF=1
****************************************************************

there are also JPO and JPE - parity
the parity flag is set if there are an even number of 1's in the low byte
the parity flag is cleared if there are an odd number of 1's in the low byte
the parity flag was used back in the days of serial communications, and is rarely used now