Search This Blog

Friday, September 23, 2011

Differentiate between ADDC and SUBB

ADDC
Does addition with carry
changes OV, AC, CY flags
This does A = A + byte + CY
used in multibyte addition
example
addition of 3456H and 2345H

CLR C        ;CY =0
MOV A, #56H    ;
ADDC A, #45H    ;
MOV R7, A    ; STORE LOWER BYTE IN R7
MOV A, #34H    ;
ADDC A, #23H    ; UPPER BYTE

Result = 3456 + 2345 = 579B

Addressing modes
Immediate:         ADDC A, #data
Register:          ADDC A, Rn
Direct:            ADDC A, 30H
Register-Indirect:     ADDC A, @R0
            ADDC A, @R1

SUBB
Does subtraction with borrow
Changes OV, Ac, CY flags
This subtracts source byte and carry flag from accumulator and puts result in accumulator.
The steps for subtraction:
Take 2's complement
Add to A
Invert carry.

CY
dest>source 0 result is positive
dest=source 0 result is 0
dest<source 1 result is negative in 2's complement

No SUB instruction in 8051
A = A - byte - CY
example:
MOV A, #45H
CLR C
SUBB A, #23H
Result 22H

Addressing modes
Immediate:         SUBB A, #data
Register:          SUBB A, Rn
Direct:            SUBB A, 30H
Register-Indirect:     SUBB A, @R0
            SUBB A, @R1

No comments:

Post a Comment