|
Programming Examples in COP8-Assembler
;---------------- 2-Byte Binary Division ---------------
;Dividend in [3,2] Divisor in [1,0] Quotient in [3,2] Remainder in [5,4] |
|
DIV: | LD | QUOTIENTLO,#X'FF | ;Division by zero |
| LD | QUOTIENTHI,#X'FF | |
| LD | B,#0 | |
| LD | A,[B+] | |
| OR | A,[B] | |
| IFEQ | A,#0a | |
| JMP | FINISH | |
| LD | QUOTIENTLO,#X'00 | |
| LD | QUOTIENTHI,#X'00 | |
| LD | TEMPCNT,#16 | ;Repeat for all bits |
| LD | B,#5 | |
| LD | [B-],#0 | |
| LD | [B],#0 | |
| LD | X,#4 | |
LSHIFT: | RC | | ;Shift left Dividend, Quotient and Remainder |
| LD | B,#2 | |
LOOP: | LD | A,[B] | |
| ADC | A,[B] | |
| X | A,[B+] | |
| IFBNE | #6 | |
| JP | LOOP | |
TSUBT: | SC | | ;Test if substractable |
| LD | B,#0 | |
| LD | A,[X+] | |
| SUBC | A,[B] | |
| LD | B,#1 | |
| LD | A,[X-] | |
| SUBC | A,[B] | |
| IFNC | | |
| JP | TEST | |
SUBT: | LD | B,#0 | ;Substract |
| LD | A,[X] | |
| SUBC | A,[B] | |
| X | A,[X+] | |
| LD | B,#1 | |
| LD | A,[X] | |
| SUBC | A,[B] | |
| X | A,[X-] | |
| LD | B,#2 | |
| SBIT | 0,[B] | |
TEST: | DRSZ | TEMPCNT | |
| JMP | LSHIFT | |
FINISH: | | ........ | |
|
|