|
4-digit decimal, up to 9999, two bytes are enough, that is, two bytes multiplied by two bytes, double-byte binary unsigned number multiplication:
; Entry conditions: the multiplicand is in R2 and R3, and the multiplier is in R6 and R7.
;Exit information: the product is in R2, R3, R4, R5.
; Affected resources: PSW, A, B, R2 ~ R7 Stack requirements: 2 bytes
MULD: MOV A, R3; calculate R3 and multiply R7
MOV B, R7
MUL AB
MOV R4, B; Temporarily store partial product
MOV R5,A
MOV A, R3; calculate R3 by R6
MOV B, R6
MUL AB
ADD A, R4; accumulate partial product
MOV R4,A
CLR A
ADDC A,B
MOV R3,A
MOV A, R2; calculate R2 multiplied by R7
MOV B, R7
MUL AB
ADD A, R4; accumulate partial product
MOV R4,A
MOV A, R3
ADDC A,B
MOV R3,A
CLR A
RLC A
XCH A, R2; calculate R2 by R6
MOV B, R6
MUL AB
ADD A, R3; accumulate partial product
MOV R3,A
MOV A, R2
ADDC A,B
MOV R2,A
RET |
|