⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 bcd_sub.asm

📁 PIC单片机开发的功能函数:加减乘除转换
💻 ASM
字号:
;*******************无符号 BCD 减法***************
;
;       This routine performs a 2 Digit Unsigned BCD Subtraction.
; It is assumed that the two BCD numbers to be subtracted are in
; locations Num_1 & Num_2. The result is the difference of Num_1 & Num_2
; ( Num_2 - Num_1) and is stored in location Num_2 and the overflow carry
; is returned in location Num_1.
;
;   Performance :
;               Program Memory  :       31
;               Clock Cycles    :       21  ( worst case )
;
;*******************************************************************
;
Num_1   equ     8       ; Overflow flow carry overwrites Num_1
result  equ     8
;
Num_2   equ     9       ; Num_2 - Num_1 overwrites Num_2
O_flow  equ     9
;
;其它寄存器自己定义
;
BCDSub 
 movf    Num_1,w
	 subwf   Num_2
	 clrf    Num_1
	 rlf     Num_1
	 btfss   STATUS,DC
	 goto    adjst1
	 btfss   Num_2,3         ; Adjust LSD of Result
	 goto    Over_1
	 btfsc   Num_2,2
	 goto    adjst1          ; Adjust LSD of Result
	 btfss   Num_2,1
	 goto    Over_1          ; No : Go for MSD
adjst1
  movlw   6
	subwf   Num_2
Over_1 
 btfss   Num_1,0         ; CY = 0 ?
	 goto    adjst2          ; Yes, adjust MSD of result
	 clrf    Num_1
	 btfss   Num_2,7         ; No, test for MSD >9
	 RETLW   0
	 btfsc   Num_2,6
	 goto    adjst2
	 btfss   Num_2,5
	 RETLW   0
adjst2
 movlw   60              ; add 6 to MSD
	 subwf   Num_2
	 clrf    Num_1
	 btfss   STATUS,CARRY    ; test if underflow
	 RETLW   0
	 movlw   1
	 movwf   Num_1
Over
    RETLW   0
;
;********************************************************************
;      测试程序(注意用法,Num_2-Num_1=Num_2)
;*********************************************************************
main    
movlw   23
	movwf   Num_1      ; Set Num_1 = 23
	movlw   99
	movwf   Num_2      ; Set Num_2 = 99
	call    BCDSub     ; After subtraction, Num_2 = 76 ( 99-23 )
;                          ;  and Num_1 = 0 ( indicates positive result )
;
self    goto    self   ; 如不是测试程序,本句无用
;
	org     1FF
	goto    main
;
	END



⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -