|
发表于 2013-9-29 15:20:42
|
显示全部楼层
;===================乘法宏定义
;32BIT 乘法 Multiplicaton
;功能: 32BIT*32BIT=64bit
;入口: 被乘数 = NUM_A1,NUM_A0,
; 乘数 = NUM_B1,NUM_B0,
;出口: 积 = NUM_D1,NUM_D0,NUM_C1,NUM_C0
;16bit
MUL_RRC:;page3
BANK_2
CLR COUNT_JSQ
BS COUNT_JSQ,0X04 ;16
ALLCLR NUM_D1,NUM_D0,NUM_C1,NUM_C0
MUL_32_32_LP:
ALLRRC NUM_B1,NUM_B0 ;乘数带C
JBS R3,C ;C=0,跳
JMP MUL_32_32_LP1
MOV A,NUM_A0
ADD NUM_D0,A
ADDC NUM_D1,NUM_A1
MUL_32_32_LP1:
ALLRRC NUM_D1,NUM_D0
ALLRRC NUM_C1,NUM_C0
DJZ COUNT_JSQ
JMP MUL_32_32_LP
RET
;====================除法宏定义
;入口:
; 被除数 = NUM_A3,NUM_A2,NUM_A1,NUM_A0
; 除数 = NUM_B3,NUM_B2,NUM_B1,NUM_B0
;出口:
; 商 = NUM_C3,NUM_C2,NUM_C1,NUM_C0
; 余数 = NUM_D3,NUM_D2,NUM_D1,NUM_D0
DIV_RLC:;page3
BANK_2
CLR COUNT_JSQ
BS COUNT_JSQ,0X05 ;32
MOV NUM_B3,NUM_B3
JBS R3,Z
JMP DIV_RLC_0
MOV NUM_B2,NUM_B2
JBS R3,Z
JMP DIV_RLC_0
MOV NUM_B1,NUM_B1
JBS R3,Z
JMP DIV_RLC_0
MOV NUM_B0,NUM_B0
JBS R3,Z
JMP DIV_RLC_0
JMP DIV_ERR
DIV_RLC_0:
ALLCLR NUM_C3,NUM_C2,NUM_C1,NUM_C0
ALLCLR NUM_D3,NUM_D2,NUM_D1,NUM_D0
;======除数不为0
DIV_32_32_LP:
ALLRLC NUM_A3,NUM_A2,NUM_A1,NUM_A0
ALLRLC NUM_D3,NUM_D2,NUM_D1,NUM_D0
;==试商
JBC R3,C
JMP DIV_32_32_LP1
SIZE_COMP NUM_D3,NUM_D2,NUM_D1,NUM_D0,NUM_B3,NUM_B2,NUM_B1,NUM_B0
JBS R3,C
JMP DIV_32_32_LP2
; BC R3,C
DIV_32_32_LP1:
MOV A,NUM_B0
SUB NUM_D0,A
SUBC NUM_D1,NUM_B1
SUBC NUM_D2,NUM_B2
SUBC NUM_D3,NUM_B3
BS R3,C
DIV_32_32_LP2:
ALLRLC NUM_C3,NUM_C2,NUM_C1,NUM_C0
DJZ COUNT_JSQ
JMP DIV_32_32_LP
BC R3,C
JMP DIV_RLC_OUT
DIV_ERR: ;溢出(除数=0)处理
MOV A,@0XFF
MOV NUM_C3,A
MOV NUM_C2,A
MOV NUM_C1,A
MOV NUM_C0,A
MOV NUM_D3,A
MOV NUM_D2,A
MOV NUM_D1,A
MOV NUM_D0,A
BS R3,C
DIV_RLC_OUT:
RET
|
|