beautypg.com

Div (divide) – Echelon Neuron User Manual

Page 95

background image

DIV (Divide)

The DIV instruction performs integer division. The DIV instruction uses the

implicit addressing mode. The instruction divides the unsigned integer dividend

value in NEXT by the unsigned integer divisor value in TOS. The quotient result

is placed in TOS. The remainder, if any, is placed in NEXT. Thus, this

instruction implements the following equation:

TOS

TOS

NEXT

, with remainder in NEXT

Division by zero has the following effects:

The quotient in TOS is set to 0xFF.

The remainder in NEXT is unchanged from the value of the dividend.

A level 3 exception (subtrap 1), if enabled, is fired. This exception does

not cause a device reset.

Recommendation: Use the _div16 or _div16s system functions to divide

unsigned or signed 16-bit numbers, and use the _div8s system function to divide

a signed 8-bit number. See _div16 (Divide, 16 Bit); _div16s (Divide Signed, 16

Bit); and _div8s (Divide Signed, 8 Bit).
The DIV instruction applies to Series 5000 and 6000 devices.

Syntax:
The DIV instruction requires no operands:

DIV

Table 29 describes the attributes of the DIV instruction.

Table 29. DIV Instruction

Instruction

Hexadecimal

Opcode

Instruction

Size (Bytes)

CPU Cycles

Required

Affect on

Carry Flag

DIV

ED

1

14

None


Example:
The following example performs the division 7/3. Before the DIV instruction

executes, TOS contains 7 and NEXT contains 3. After the DIV instruction

executes, TOS contains 2 (7/3 = 2, with remainder) and NEXT contains 1 (the

remainder).

pushs #3 ; (3, -, -)

pushs #7 ; (7, 3, -)

div ; (2, 1, -)

Neuron Assembly Language Reference

85