beautypg.com

Sub (subtract) – Echelon Neuron User Manual

Page 135

background image

SUB (Subtract)

The SUB instruction subtracts two numbers. The SUB instruction uses the

direct addressing mode, in two forms, subtract NEXT from TOS, and subtract

TOS from NEXT:

The SUB NEXT,TOS instruction retrieves both TOS and NEXT from the

data stack and subtracts NEXT from TOS. TOS and NEXT are

consumed, and the result is placed in TOS. The operation modifies the

Carry flag as result of the unsigned subtraction: if the value of TOS

exceeds the value of NEXT (indicating that the result would be negative),

the SUB instruction sets the Carry flag; otherwise the instruction clears

the Carry flag.

The SUB TOS,NEXT instruction retrieves both TOS and NEXT from the

data stack and subtracts TOS from NEXT. TOS and NEXT are

consumed, and the result is placed in TOS. The operation modifies the

Carry flag as result of the unsigned subtraction: if the value of NEXT

exceeds the value of TOS (indicating that the result would be negative),

the SUB instruction sets the Carry flag; otherwise the instruction clears

the Carry flag.

The SUB instruction applies to Series 3100, 5000, and 6000 devices.

Syntax:
The SUB instruction requires two operands:

SUB NEXT,TOS

SUB TOS,NEXT

Table 56 describes the attributes of the SUB instruction.

Table 56. SUB Instruction

Instruction

Hexadecimal

Opcode

Instruction

Size (Bytes)

CPU Cycles

Required

Affect on

Carry Flag

SUB NEXT,TOS 57

1

4

Modified

SUB TOS,NEXT 55

1

4

Modified


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

pushs #3 ; (3, -, -)

pushs #2 ; (2, 3, -)

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

pushs #3 ; (3, 1, -)

pushs #2 ; (2, 3, 1)
sub tos,next

; (255, 1, -)

Neuron Assembly Language Reference

125