C161U
System Programming
Preliminary Data Sheet
402
02.2000
PRELIMINARY
PRE
LI
M
INAR
Y
- E
XC
ER
PT
-
register is read. Because an interrupt can be acknowledged before the contents of
register MD are saved, this flag is required to alert interrupt routines, which require the
use of the multiply/divide hardware, so they can preserve register MD. This register,
however, only needs to be saved when an interrupt routine requires use of the MD
register and a previous task has not saved the current result. This flag is easily tested by
the Jump-on-Bit instructions.
Multiplication or division is simply performed by specifying the correct (signed or
unsigned) version of the multiply or divide instruction. The result is then stored in register
MD. The overflow flag (V) is set if the result from a multiply or divide instruction is greater
than 16 bits. This flag can be used to determine whether both word halfs must be
transferred from register MD. The high portion of register MD (MDH) must be moved into
the register file or memory first, in order to ensure that the MDRIU flag reflects the correct
state.
The following instruction sequence performs an unsigned 16 by 16-bit multiplication:
SAVE:
JNB
MDRIU, START
;Test if MD was in use.
SCXT
MDC, #0010H
;Save and clear control register,
;leaving MDRIU set
;(only required for interrupted
;multiply/divide instructions)
BSET
SAVED
;Indicate the save operation
PUSH
MDH
;Save previous MD contents...
PUSH
MDL
;...on system stack
START:
MULU
R1, R2
;Multiply 1616 unsigned, Sets MDRIU
JMPR
cc_NV, COPYL
;Test for only 16-bit result
MOV
R3, MDH
;Move high portion of MD
COPYL:
MOV
R4, MDL
;Move low portion of MD, Clears MDRIU
RESTORE:
JNB
SAVED, DONE
;Test if MD registers were saved
POP
MDL
;Restore registers
POP
MDH
POP
MDC
BCLR
SAVED
;Multiplication is completed,
;program continues
DONE:
...
The above save sequence and the restore sequence after COPYL are only required if
the current routine could have interrupted a previous routine which contained a MUL or
DIV instruction. Register MDC is also saved because it is possible that a previous
routine's Multiply or Divide instruction was interrupted while in progress. In this case the
information about how to restart the instruction is contained in this register. Register
MDC must be cleared to be correctly initialized for a subsequent multiplication or