beautypg.com

Sbc (subtract with carry) – Echelon Neuron User Manual

Page 124

background image

SBC (Subtract with Carry)

The SBC instruction subtracts two numbers, and uses the value of the Carry flag

as input to the subtrahend. The SBC instruction uses the direct addressing

mode. The SBC instruction retrieves both TOS and NEXT from the data stack,

adds the value of the Carry flag to TOS, and then subtracts TOS (the

subtrahend) from NEXT (the minuend). TOS and NEXT are consumed, and the

result (the difference) is placed in TOS. The operation modifies the Carry flag as

result of the unsigned subtraction: if the value of TOS plus the value of the

Carry flag exceeds the value of NEXT (indicating that the result would be

negative), the SBC instruction sets the Carry flag; otherwise the instruction

clears the Carry flag.
The SBC instruction applies to Series 3100, 5000, and 6000 devices.

Syntax:
The SBC instruction requires two operands:

SBC NEXT,TOS

Table 48 describes the attributes of the SBC instruction.

Table 48. SBC Instruction

Instruction

Hexadecimal

Opcode

Instruction

Size (Bytes)

CPU Cycles

Required

Affect on

Carry Flag

SBC NEXT,TOS 56

1

4

Used, modified


Example:
The following example performs the operation 3-2. The example assumes that

the Carry flag is not set.

pushs #3 ; (3, -, -)

pushs #2 ; (2, 3, -)

sbc next,tos ; (1, -, -)

The value of TOS after this code executes is 1 because (3+Carry)-2 = 1. In this

case, the value of the Carry flag is used for the subtraction, and then modified

(cleared) because the unsigned subtraction did not require an extra carry bit.

114

Neuron Assembly Language Instruction Statements