C161U
System Programming
Preliminary Data Sheet
403
02.2000
PRELIMINARY
PRE
LI
M
INAR
Y
- E
XCE
RP
T
-
division. The old MDC contents must be popped from the stack before the RETI
instruction is executed.
For a division the user must first move the dividend into the MD register. If a 16/16-bit
division is specified, only the low portion of register MD must be loaded. The result is also
stored into register MD. The low portion (MDL) contains the integer result of the division,
while the high portion (MDH) contains the remainder.
The following instruction sequence performs a 32 by 16-bit division:
MOV
MDH, R1
;Move dividend to MD register. Sets MDRIU
MOV
MDL, R2
;Move low portion to MD
DIV
R3
;Divide 32/16 signed, R3 holds divisor
JMPR
cc_V, ERROR
;Test for divide overflow
MOV
R3, MDH
;Move remainder to R3
MOV
R4, MDL
;Move integer result to R4. Clears MDRIU
Whenever a multiply or divide instruction is interrupted while in progress, the address of
the interrupted instruction is pushed onto the stack and the MULIP flag in the PSW of the
interrupting routine is set. When the interrupt routine is exited with the RETI instruction,
this bit is implicitly tested before the old PSW is popped from the stack. If MULIP=’1’ the
multiply/divide instruction is re-read from the location popped from the stack (return
address) and will be completed after the RETI instruction has been executed.
Note: The MULIP flag is part of the context of the interrupted task. When the
interrupting routine does not return to the interrupted task (eg. scheduler switches
to another task) the MULIP flag must be set or cleared according to the context of
the task that is switched to.
BCD Calculations
No direct support for BCD calculations is provided in the C161U. BCD calculations are
performed by converting BCD data to binary data, performing the desired calculations
using standard data types, and converting the result back to BCD data. Due to the
enhanced performance of division instructions binary data is quickly converted to BCD
data through division by 10D. Conversion from BCD data to binary data is enhanced by
multiple bit shift instructions. This provides similar performance compared to instructions
directly supporting BCD data types, while no additional hardware is required.
21.1
Stack Operations
The C161U supports two types of stacks. The system stack is used implicitly by the
controller and is located in the internal RAM. The user stack provides stack access to the