SUB

Instruction: Subtract two unsigned values.

SUB Value1, < # > Value2


Result: Difference of unsigned Value1 and unsigned Value2 is stored in Value1.

  • Value1 (d-field) is the register containing the value to subtract Value2 from, and is the destination in which to write the result.
  • Value2 (s-field) is a register or a 9-bit literal whose value is subtracted from Value1.

Opcode Table:

–INSTR–  ZCRI –CON–    –DEST–         –SRC–

Z Result

C Result

Result

Clocks

 100001    001i    1111    ddddddddd    sssssssss

D - S = 0

Unsigned Borrow

Written

4

Concise Truth Table:

In

Out

Destination1

Source

Z

C

Effects

Destination

Z

C

$0000_0002; 2

$0000_0001; 1

-

-

wz wc

$0000_0001; 1

0

0

$0000_0002; 2

$0000_0002; 2

-

-

wz wc

$0000_0000; 0

1

0

$0000_0002; 2

$0000_0003; 3

-

-

wz wc

$FFFF_FFFF; 4,294,967,295

0

1

1 Both Source and Destination are treated as unsigned values.

Explanation

SUB subtracts the unsigned Value2 from the unsigned Value1 and stores the result into the Value1 register.

If the WZ effect is specified, the Z flag is set (1) if Value1Value2 equals zero. If the WC effect is specified, the C flag is set (1) if the subtraction resulted in an unsigned borrow (32-bit overflow). The result is written to Value1 unless the NR effect is specified.

To subtract unsigned, multi-long values, use SUB followed by SUBX. See SUBX for more information.

Unless otherwise noted, content on this site is licensed under the
Creative Commons Attribution-ShareAlike 4.0 International License.