CS255 Syllabus

The integer negation (NEG) instruction

• Negation

• Negation:

 Negation = ontain the representation for the negative value of the input value

• The representation of the negative value depends on the (value) representation system:

• In a deciaml number system:

 ``` Input value (representation) | Negative representation -------------------------------+------------------------------- 5 | -5 -5 | 5 .... | .... ```

• In a 8 bits 2's complement number system (used by a computer to represent integer (= whole number) values in byte typed variables):

 ``` Input value (representation) | Negative representation -------------------------------+------------------------------- 00000101 (= 510) | 11111011 (= -510) 11111011 (= -510) | 00000101 (= 510) .... | .... ```

• In a 16 bits 2's complement number system (used by a computer to represent integer (= whole number) values in short typed variables):

 ``` Input value (representation) | Negative representation -------------------------------+------------------------------- 0000000000000101 (= 510) | 1111111111111011 (= -510) 1111111111111011 (= -510) | 0000000000000101 (= 510) .... | .... ```

• The negation NEG instruction

• The NEG instruction:

 The NEG instruction in M68000 computes the representation of the negative value of an input integer value in 2's complement code

• There are 3 forms of the NEG instruction:

 ``` NEG.B Dn // Negates the byte representation // of the int value in data register Dn NEG.W Dn // Negates the short (16 bits) representation // of the int value in data register Dn NEG.L Dn // Negates the int (32 bits) representation // of the int value in data register Dn ```

• Examples:

 ``` +----------+----------+----------+----------+ D0 = | 00000000 | 10101010 | 11110000 | 00001111 | +----------+----------+----------+----------+ NEG.B D0 (use 8 bit operand in D0 !) Result: +----------+----------+----------+----------+ D0 = | 00000000 | 10101010 | 11110000 | 11110001 | +----------+----------+----------+----------+ Because if we negate 00001111, we will get: 11110001 ```

 ``` +----------+----------+----------+----------+ D0 = | 00000000 | 10101010 | 11110000 | 00001111 | +----------+----------+----------+----------+ NEG.W D0 (use 16 bit operand in D0 !) Result: +----------+----------+----------+----------+ D0 = | 00000000 | 10101010 | 00001111 | 11110001 | +----------+----------+----------+----------+ Because if we negate: 11110000 00001111 we will get: 00001111 11110001 ```