# SUB Instruction

Subtracts two binary operands and stores the result in the destination operand.
Two different methods are allowed:
1. Subtract an effective address from a data register.
2. Subtract a data register from an effective address.

ADDRESS METHODS: 1) Dn, An, (An), (An)+, -(An), x(An), x(An,xr.s), x.w, x.l, x(PC), x(PC,xr.s), #x

ADDRESS METHODS: 2) (An), (An)+, -(An), x(An), x(An,xr.s), x.w, x.l
DATA LENGTH: Byte, word, longword
When using an address register as destination, byte is not allowed.

FLAGS: | X - Set if a loan was required from the most significant bit, otherwise 0.
N - S
Z - S
C - Same as X
V - S

SYNTAX: | SUB Dn,<ea>
SUB <ea>,Dn

When an address register is the destination, you use SUBA. Many assemblers will automatically choose SUBA if you write SUB with an address register as destination.

EXAMPLE CODE:

SUB.B D0,D1 subtracts the lower 8 bits of D0 from D1, does not change the upper 24 bits of D0 or D1
SUBW D0,D1 subtracts the lower 16 bits of D0 from D1, does not change the upper 16 bits of D0 or D1
SUB.L D0,D1 subtracts all 32 bits of D0 from D1