Mnemonics

SBC

8-bit Arithmetic Group | 16-Bit Arithmetic Group
Expansion:
SuBtract and Carry
Usage:
sbc {a|hl}, {r|rr}

Subtract with carry works by subtracting a value from an accumulator (register a or hl) by the provided registry value. This instruction is useful for performing multi-byte or multi-word subtraction, where the carry flag indicates if there was a borrow from the previous operation.

Z80.CPU instructions
Instruction Description Opcode
SBC A, A Subtract register A by itself 9F
SBC A, B Subtract register A by value in register B 98
SBC A, C Subtract register A by value in register C 99
SBC A, D Subtract register A by value in register D 9A
SBC A, E Subtract register A by value in register E 9B
SBC A, H Subtract register A by value in register H 9C
SBC A, L Subtract register A by value in register L 9D
SBC A, {??} Subtract register A by value in immediate value DE {??}
SBC A, (HL) Subtract register A by value in address in HL 9E
SBC A, (IX+displacement) Subtract register A by value in address IX + displacement DD9E ??
SBC A, (IY+displacement) Subtract register A by value in address IY + displacement FD9E ??
SBC HL, BC Subtract register HL by value in register BC ED42
SBC HL, DE Subtract register HL by value in register DE ED52
SBC HL, HL Subtract register HL by itself ED62
SBC HL, SP Subtract register A by value in register SP ED72

Example

; example ld a, 20 ; load the value 20 into register A ld b, 5 ; load the value 5 into register B sbc a, b ; subtract B and the carry flag from A (A = A - B - Carry) ; A = 15 if the carry flag was 0 initially ; or A = 14 if the carry flag was 0 initially

Second

ENTRY_POINT equ $8000 ; start of the empty memory org ENTRY_POINT ; start ; ... code here ret ; return to the system end ENTRY_POINT ; end of file marker

Additional description area

  • Point 1
  • If decrementing allows the BC to go to 0 or if A equals the value at the memory location pointed to by HL (A = (HL)), the instruction is terminated2. If BC is not 0 and A ≠ (HL), the program counter is decremented by two and the instruction is repeated2.
  • Point 3

See also