This the multi-page printable view of this section.Click here to print.

Return to the regular view of this page.

SBC Subtract with Borrow from Accumulator

Subtract with Borrow

Table of Contents

Subtracts the data in the operand with the contents of the accumulator. Subtract 1 from the result if the carry flag is clear. Store the final result in the accumulator.

Binary/Decimal mode

If the d flag is clear then binary subtraction is performed. If the d flag set then Binary Coded Decimal (BCD) subtraction is performed.

Data size

On all processors, the data subtracted from memory is 8-bit. However, for 16-bit processors with the m flag is clear then the data subtracted is 16-bit with the low-order 8-bits at the effective address and the high-order 8-bits at the effective address plus one.

Multi-precision arithmetic

In multi-precision (multi-word) arithmetic, the carry flag should be set before the low-order words are subtracted. The subtraction will generate a new carry flag value based on that subtraction which will then be passed on to the next word.

For example, to subtract 1 from a 16-bit value at &70 on 8-bit processors:

1  SEC      ; Set carry before first subtraction
2  LDA &70  ; Subtract 1 from low-order byte
3  SBC #1
4  STA &70
5  LDA &71  ; Subtract 0 to high order byte
6  SBC #0   ; This will subtract 1 if carry was clear
7  STA &71  ; from the low-order byte
Flags Affected
Flags
nv----zc
nSet if most-significant bit of result is set
vSet if signed overflow
zSet if result is zero
cSet if unsigned borrow not required, clear if required
Instructions
SyntaxOpcode Available on: # of # of Addressing Mode
(hex) 6502 65C02 65816 bytes cycles
SBC #constE9 x x x 21 22, 5 Immediate
SBC addrED x x x 3 42, 5 Absolute
SBC longEF x 4 52, 5 Absolute Long
SBC dpE5 x x x 2 32, 3, 5 Direct Page
SBC (dp)F2 x x 2 52, 3, 5 Direct Page Indirect
SBC [dp]E7 x 2 62, 3, 5 Direct Page Indirect Long
SBC addr,XFD x x x 3 42, 4, 5 Absolute Indexed X
SBC long,XFF x 4 52, 5 Absolute Long Indexed X
SBC addr,YF9 x x x 3 42, 4, 5 Absolute Indexed Y
SBC dp,XF5 x x x 2 42, 3, 5 Direct Page Indexed X
SBC (dp,X)E1 x x x 2 62, 3, 5 Direct Page Indexed Indirect X
SBC (dp),YF1 x x x 2 52, 3, 4, 5 Direct Page Indirect Indexed Y
SBC [dp],YF7 x 2 62, 3, 5 Direct Page Indirect Long Indexed Y
SBC sr,SE3 x 2 42, 5 Stack Relative
SBC (sr,S),YF3 x 2 72, 5 Stack Relative Indirect Indexed Y

Notes:

  1. 65816: Add 1 byte if m=0 (16-bit memory/accumulator)
  2. 65816: Add 1 cycle if m=0 (16-bit memory/accumulator)
  3. 65816: Add 1 cycle if low byte of Direct Page register is not 0
  4. Add 1 cycle if adding index crosses a page boundary
  5. 65C02: Add 1 cycle if d=1