Write a subroutine Div_16 to implement double-byte unsigned number division. Define variables by yourself, where:
ACCALO; store the lower 8 bits of the dividend
ACCAHI; store the high 8 bits of the dividend
ACCBLO; store the divisor 8 bits
ACCCLO; store remainder 8 bits
ACCCHI; Depositor 8 digits
Using the shift method, let the dividend be ACCA, the divisor be ACCBLO, the quotient be ACCCHI (initial value is 0), and the remainder be ACCCLO (initial value is 0). ACCA is shifted left from high to low and enters the ACCCLO unit. After each shift, the values of the ACCCLO unit and ACCBLO are compared. If ACCCLO ≥ ACCBLO, the value of the quotient unit of this bit is set to 1, and then ACCBLO is subtracted from ACCCLO, otherwise no operation is performed. Until all ACCA enters the ACCCLO unit. At this time, the quotient is stored in ACCCHI and the remainder is stored in ACCCLO.
Program flowchart:
list p=16f877A ; Indicate the processor type used
#include
__CONFIG _CP_OFF & _WDT_OFF & _BODEN_OFF & _PWRTE_OFF & _HS_OSC & _WRT_OFF & _LVP_OFF & _CPD_OFF
;*****************Variable definitions*******************************************************
ACCALO EQU 0x20 ; store the lower 8 bits of the dividend
ACCAHI EQU 0x21 ; store the high 8 bits of the dividend
ACCBLO EQU 0x22 ; store the divisor 8 bits
ACCCLO EQU 0x23 ; Store the remainder 8 bits
ACCCHI EQU 0x24 ; Stores 8 bits
COUNT EQU 0x25 ; store loop variables
;*******************************************************************************
ORG 0x0000 ; Reset entry address
nop ; compatible with ICD debugging tools, nop must be added
goto Main; Jump to Main function
;*****************************Main function code**********************************
Main
MOVLW 0x2A ; send the high 8 bits of the dividend
MOVWF ACCAHI
MOVLW 0x3B ; send the lower 8 bits of the dividend
MOVWF ACCALO
MOVLW 0x4C ; send divisor
MOVWF ACCBLO
MOVLW .16 ; Initialize loop variables
MOVWF COUNT
CLRF ACCCLO ; Clear result unit
CLRF ACCCHI
CALL Div_16 ; Call the subroutine to solve, the result should be quotient 0x8E, remainder 0x13
nop
goto $ ; stop
;**************************Compress BCD code to binary subroutine********************
ORG 0X0100
Div_16
RLF ACCALO
RLF ACCAHI
RLF ACCCLO ; The dividend is shifted left from high to low into the remainder unit
MOVF ACCBLO,W
BSF STATUS, C ; C position 1
SUBWF ACCCLO,W ; Compare remainder unit with divisor unit
BTFSC STATUS,C ; 若ACCCLO>=ACCBLO
CALL SUB_C_B ; then the bit quotient unit is set to 1, and the remainder unit is subtracted from the divisor, otherwise the bit quotient unit is set to 0
RLF ACCCHI
DECFSZ COUNT,F
GOTO Div_16
RETURN
SUB_C_B
MOVF ACCBLO,W ; Subtract the divisor from the remainder unit
SUBWF ACCCLO,F
RETURN
;*****************************************************************************
END ; End of program
Previous article:PIC Microcontroller Introduction_Instruction System
Next article:Teach you how to use PIC microcontroller to drive relay
- Popular Resources
- Popular amplifiers
- Learn ARM development(16)
- Learn ARM development(17)
- Learn ARM development(18)
- Embedded system debugging simulation tool
- A small question that has been bothering me recently has finally been solved~~
- Learn ARM development (1)
- Learn ARM development (2)
- Learn ARM development (4)
- Learn ARM development (6)
Professor at Beihang University, dedicated to promoting microcontrollers and embedded systems for over 20 years.
- LED chemical incompatibility test to see which chemicals LEDs can be used with
- Application of ARM9 hardware coprocessor on WinCE embedded motherboard
- What are the key points for selecting rotor flowmeter?
- LM317 high power charger circuit
- A brief analysis of Embest's application and development of embedded medical devices
- Single-phase RC protection circuit
- stm32 PVD programmable voltage monitor
- Introduction and measurement of edge trigger and level trigger of 51 single chip microcomputer
- Improved design of Linux system software shell protection technology
- What to do if the ABB robot protection device stops
- Analysis of the application of several common contact parts in high-voltage connectors of new energy vehicles
- Wiring harness durability test and contact voltage drop test method
- From probes to power supplies, Tektronix is leading the way in comprehensive innovation in power electronics testing
- From probes to power supplies, Tektronix is leading the way in comprehensive innovation in power electronics testing
- Sn-doped CuO nanostructure-based ethanol gas sensor for real-time drunk driving detection in vehicles
- Design considerations for automotive battery wiring harness
- Do you know all the various motors commonly used in automotive electronics?
- What are the functions of the Internet of Vehicles? What are the uses and benefits of the Internet of Vehicles?
- Power Inverter - A critical safety system for electric vehicles
- Analysis of the information security mechanism of AUTOSAR, the automotive embedded software framework
- Original goods, new goods in bulk, refurbished goods, disassembled parts, cut board ICs...what do they mean exactly?
- Does the ripple of the power supply have any effect on the output of the filter?
- How to do it?
- Eight common methods for electronic product maintenance
- Thanks to EE for the New Year gift
- Understanding Balun in one article (functional principle, performance parameters, basic types)
- How to quickly master the principles and functions of different types of MCUs
- Infineon XC2000 family MCU applications in automotive embedded microcontrollers
- [ESP32-Korvo Review] (8) Voice Recognition Usage Test
- How to burn the program into the Anxinke Bluetooth PB-03f kit?