Texas Instruments MSC1210 User Manual

Page 214

Advertising
background image

Performing Subtractions (SUBB)

16-20

16.18 Performing Subtractions (SUBB)

The SUBB instruction provides a way to perform 8-bit subtraction. All subtrac-
tion involves subtracting some number or register from the accumulator and
leaving the result in the accumulator. The original value in the accumulator is
always overwritten with the result of the subtraction.

SUBB A,#25h

;Subtract 25h from whatever value is in
;the accumulator

SUBB A,40h

;Subtract contents of IRAM address 40h from
;the accumulator

SUBB A,R4

;Subtract the contents of R4 from the
;accumulator

The SUBB instruction always includes the carry bit in the subtract operation.
That means if the accumulator holds the value 38

H

and the carry bit is set, sub-

tracting 6

H

will result in 31

H

(38

H

– 6

H

– carry bit).

Note:

Due to SUBB always including the carry bit in its operation, it is necessary
to always clear the carry bit (CLR C) before executing the first SUBB in a sub-
traction operation, so that the prior status of the carry flag does not affect the
instruction.

SUBB sets and clears the carry, auxiliary carry, and overflow bits in much the
same way as the ADD and ADDC instructions.

SUBB sets the carry bit if the number being subtracted from the accumulator
is larger than the value in the accumulator. In other words, the carry bit is set
if a borrow is needed for bit 7. Otherwise, the carry bit is cleared.

The auxiliary carry (AC) bit is set if a borrow is needed for bit 3; otherwise, it
is cleared.

The overflow (OV) bit is set if a borrow into bit 7 but not into bit 6, or into bit 6
but not into bit 7. This is used when subtracting signed integers. If subtracting
a negative value from a positive value produces a negative number, OV is set.
Likewise, if subtracting a positive number from a negative number produces
a positive number, the OV flag is also set.

Advertising