Преобразование двоичного формата в десятичный
;************************************************* *******************
; Binary To BCD Conversion Routine
; This routine converts a 16 Bit binary Number to a 5 Digit
; The 16 bit binary number is input in locations H_byte and
; L_byte with the high byte in H_byte.
; The 5 digit BCD number is returned in R0, R1 and R2 with R0
; containing the MSD in its right most nibble.
;
; Performance :
; Program Memory : 35
; Clock Cycles : 885
;
;
; Program: B16TOBCD.ASM
; Revision Date:
; 1-13-97 Compatibility with MPASMWIN 1.40
;
;************************************************* ******************;
;
count equ 75
temp equ 76
;
H_byte equ 70
L_byte equ 71
R0 equ 72 ; RAM Assignments
R1 equ 73
R2 equ 74
X_D
call B2_BCD
MOVLW 1
XORWF COUNTER,W
BTFSC STATUS,Z
GOTO D_MANY
MOVLW 2
XORWF COUNTER,W
BTFSC STATUS,Z
GOTO D_LITR
MOVLW 3
XORWF COUNTER,W
BTFSC STATUS,Z
GOTO D_PRICE
B2_BCD bcf STATUS,0 ; clear the carry bit
movlw .16
movwf count
clrf R0
clrf R1
clrf R2
loop16 rlf L_byte, F
rlf H_byte, F
rlf R2, F
rlf R1, F
rlf R0, F
;
decfsz count, F
goto adjDEC
RETLW 0
;
adjDEC movlw R2
movwf FSR
call adjBCD
;
movlw R1
movwf FSR
call adjBCD
;
movlw R0
movwf FSR
call adjBCD
;
goto loop16
;
adjBCD movlw 3
addwf 0,W
movwf temp
btfsc temp,3 ; test if result › 7
movwf 0
movlw 30
addwf 0,W
movwf temp
btfsc temp,7 ; test if result › 7
movwf 0 ; save as MSD
RETLW 0
|