Section 04 Part 03 – The NEG Instruction “Polarity, or action and reaction, we meet in every part of nature; in darkness and light; in heat and cold; in the ebb and flow of water; in male and female; in the equation of quantity and quality; in the fluids of the animal body; in the systole an” ~Ralph Waldo Emerson

Introduction

NEG – NEGate

This instruction will reverse the polarity of the destination operand, from positive to negative, or from negative to positive.

Examples

In the previous part, we were looking at signed data for positive and negative.  This instruction will allow you to change a positive number into a negative number, or vise-versa.

Now let’s take this example below:

 neg.b     d0

A byte of d0 is negated.

• If d0 started with 00220002, after the instruction d0 will contain 002200FE

You’ll notice that the byte in d0 was changed from 02 to FE, basically +2 to -2.

• If d0 started with FED0C4E4, after the instruction d0 will contain FED0C41C

Here, you’ll notice that the byte E4 has changed to 1C, basically -1C to +1C.

Positive to Negative, Negative to Positive, and that’s the general rule.  However, there are certain cases where negation will have no effect, for example:

• If d0 started with 0890F300, after the instruction d0 will contain 0890F300
• If d0 started with 0890F380, after the instruction d0 will contain 0890F380

Using the 00 example, 00 is neutral as far as negate is concerned.  It represents nothing, so there’s nothing to negate.  The 80 example on the other hand is in a similar predicament, but it’s harder to explain.

• When 7E is negated, it results in 82 (-7E), and 82 negated is 7E.
• When 7F is negated, it results in 81 (-7F), and 81 negated is 7F.
• When 80 is negated, it results in 80 (-80), and 80 negated is 80.

As you can see, 80 seems to have its own “neutral” position, being the exact opposite of 00:

 ... FC FD FE FF 00 01 02 03 04 ... ... 7C 7D 7E 7F 80 81 82 83 84 ...

It is of course important to remember, that 00 is still technically positive, while 80 is still technically negative.

The NEG instruction can be used on memory, directly or by using an address register in various ways:

 neg.w     \$00004000           neg.l     (a2)           neg.w     (a2)+           neg.b     -(a2)           neg.w     \$0C(a2)

You cannot of course use NEG on address registers directly:

 neg.l     a2