;----------------------------------------------------------------- ; EX65.ASM UNSIGNED MULTIPLY - I C.P. Diduch 2001 ; ; Using repeated addition, compute the product R0 * R1 and store ; into R3 and R2. The 16-MSB's of the product are stored in R3 ; and the 16-LSB's of the product are stored in R2. Assume R0 and ; R1 are read at input ports 0x0000 and 0x0001 and the 32-bit ; product is written to output ports 0x0003 and 0x0002. ; ; Author(s): ; Signature(s): Date: ;----------------------------------------------------------------- .ORG 0x8000 ; "assign the following to ROM" ; ; void main(void) { ; ; do { L0: LOADP R0, 0x0000 ; R0 = inport(0x0000) ; LOADP R1, 0x0001 ; R1 = inport(0x0001) ; XOR R3, R3, R3 ; R3 = 0 ; XOR R2, R2, R2 ; R2 = 0 ; ; L1: SUBL NULL, R0, 0 ; while (R0 != 0) { JMPZ L3 ; ADD R2, R2, R1 ; R2 = R2 + R1 ; JMPNC L2 ; if (R2 overflows) { ADDL R3, R3, 1 ; R3 = R3 + 1 ; ; } L2: SUBL R0, R0, 1 ; R0 = R0 - 1 ; JMP L1 ; } ; L3: STOREP 0x0002, R2 ; outport(0x0002, R2) ; STOREP 0x0003, R3 ; outport(0x0003, R3) ; JMP L0 ; } ; }