
C165UTAH
System Programming
Data Sheet
475
2001-02-23
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
SCXT
MDRIU, START
MDC, #0010H
;Test if MD was in use.
;Save and clear control register,
;leaving MDRIU set
;(only required for interrupted
;multiply/divide instructions)
;Indicate the save operation
;Save previous MD contents...
;...on system stack
BSET
PUSH
PUSH
START:
MULU
JMPR
MOV
COPYL:
MOV
RESTORE:
JNB
POP
POP
POP
BCLR
SAVED
MDH
MDL
R1, R2
cc_NV, COPYL
R3, MDH
;Multiply 16·16 unsigned, Sets MDRIU
;Test for only 16-bit result
;Move high portion of MD
R4, MDL
;Move low portion of MD, Clears MDRIU
SAVED, DONE
MDL
MDH
MDC
SAVED
;Test if MD registers were saved
;Restore registers
;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