给使用应广单片机 做开发的初学者一个入门的例程
这是一个 电推剪的 案子 最先开始的样子 刚拿到 应广的单片机 第一次尝试做电推剪
由于这是一个公司真实的案子 所以请见谅 给大家的是一个 刚开始的版本
有一段 32 bit /32 bit 的除法 改自 匠人手记
;;====================除法宏定义
;;入口:
;; 被除数 = 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:
CLEAR COUNT_JSQ
SET1 COUNT_JSQ,0X05 ;32
MOV A,0x00
CEQSN NUM_B3,A
;MOV NUM_B3,NUM_B3
;T1SN Z
GOTO DIV_RLC_0
;MOV NUM_B2,NUM_B2
;T1SN Z
; MOV A,0x00
CEQSN NUM_B2,A
GOTO DIV_RLC_0
;MOV NUM_B1,NUM_B1
;T1SN Z
; MOV A,0x00
CEQSN NUM_B1,A
GOTO DIV_RLC_0
;MOV NUM_B0,NUM_B0
;T1SN Z
; MOV A,0x00
CEQSN NUM_B0,A
GOTO DIV_RLC_0
GOTO 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
;==试商
T0SN C
GOTO DIV_32_32_LP1
;SIZE_COMP NUM_D3,NUM_D2,NUM_D1,NUM_D0,NUM_B3,NUM_B2,NUM_B1,NUM_B0
MOV A,NUM_D3
;MOV RTMP_MAC,A
;MOV A,NUM_B3
;SUB A,RTMP_MAC
COMP A,NUM_B3
T0SN C
GOTO COMP_Small
T1SN Z
GOTO COMP_LARGE
MOV A,NUM_D2
;MOV RTMP_MAC,A
;MOV A,NUM_B2
;SUB A,RTMP_MAC
COMP A,NUM_B2
T0SN C
GOTO COMP_Small
T1SN Z
GOTO COMP_LARGE
MOV A,NUM_D1
;MOV RTMP_MAC,A
;MOV A,NUM_B1
;SUB A,RTMP_MAC
COMP A,NUM_B1
T0SN C
GOTO COMP_Small
T1SN Z
GOTO COMP_LARGE
MOV A,NUM_D0
;MOV RTMP_MAC,A
;MOV A,NUM_B0
;SUB A,RTMP_MAC
COMP A,NUM_B0
T0SN C
GOTO COMP_Small
T1SN Z
GOTO COMP_LARGE
; GOTO COMP_LARGE
COMP_LARGE:
SET1 C
GOTO SIZE_COMP_OUT
COMP_Small:
SET0 C
GOTO SIZE_COMP_OUT
SIZE_COMP_OUT:
;
;*/
T1SN C
GOTO DIV_32_32_LP2
; SET0 C
DIV_32_32_LP1:
MOV A,NUM_B0
SUB NUM_D0,A
SUBCC NUM_D1,NUM_B1
SUBCC NUM_D2,NUM_B2
SUBCC NUM_D3,NUM_B3
SET1 C
DIV_32_32_LP2:
ALLRLC NUM_C3,NUM_C2,NUM_C1,NUM_C0
DZSN COUNT_JSQ
GOTO DIV_32_32_LP
SET0 C
GOTO 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
SET1 C
DIV_RLC_OUT:
RET
|