# SBCD Instruction

The instruction SBCD (Subtract BCD with extend) subtracts two bytes in BCD-form. The difference (destination - source - X flag) is stored in the destination register.
ADDRESS METHODS: Dn, -(An)
There are two ways to use this instruction:
1. Subtract a data register from a data register (address method Dn). The lower byte in the source register is subtracted from the lower byte in the destination register, where the answer is stored.
2. Subtract memory from memory. This way, you can subtract big numbers stored in many bytes. Since you only can use -(An) you must start on the highest byte (the least significant digits in the BCD number) and work down. If there is a carry, the X bit is set, which will be subtracted from the next byte.
DATA LENGTH: Byte

FLAGS: | X - Set if a loan was required when subtracting, else cleared
N - undef
Z - Cleared if the result was 0, else unaffected
C - Same as X
V - undef

The Z flag is cleared if the result is not 0. This way, you can see if the answer, after a series of subtractions, is zero or not. First, you have to set the Z flag (done by comparing a register with itself). Then do the subtraction, and if the Z flag is set, the BCD number is zero.

SYNTAX: | SBCD Dx,Dy
SBCD -(Ax),-(Ay)

EXAMPLE CODE:

SBCD.B D0,D1 Subtracts the 2 BCD numbers in D0 and D1 and stores the answer in D1