The shift-subtraction algorithm is used. The source code is as follows:
1 ;//////////////////////////////////////////////// /////////////////////////////////
2 ; Function: div_u16_u8
3 ; Description: Unsigned double byte divided by single byte
4; Entry: (R6,R7)/(R0)
5; Export: (R6,R7).(R5)
6 ;Note: The remainder is in R5; when OV=1, it indicates overflow
7 ; Impact: A,B,R0,R5,R6,R7
8 div_u16_u8: mov r5,#0
9 mov b,#16
10 #ifdef __SPEED_P__
11 mov a,r6 ; When the high byte is less than the divisor, just shift 8 times
12 jz _du168_line_03
13 clr c
14 subb a,r0
15 jnc_du168_loop_00
16
17 mov b,#8
18 clr a
19 xch a,r7
20 xch a,r6
21 xch a,r5
22 sjmp _du168_loop_00
twenty three
24 _du168_line_03: mov a,r7
25 mov b,r0
26 div ab
27 mov r7,a
28 mov r5,b
29 sjmp _du168_line_04
30 #endif
31 _du168_loop_00: clr c
32
33 mov a,r7 ; shift left
34 rlc a
35 mov r7,a
36
37 mov a,r6
38 rlc a
39 mov r6,a
40
41 mov a,r5
42 rlc a
43 mov r5,a
44
45 mov F0,c ; shift out bit = 1, or when the high byte is enough to subtract, the quotient + 1
46 clr c
47 subb a,r0
48 anl c,/F0
49 jc _du168_line_01
50 mov r5,a
51 inc r7
52 _du168_line_01: djnz b,_du168_loop_00
53
54 _du168_line_04: mov a,r5 ; round up
55 add a,r5
56 jc _du168_line_02
57 subb a,r0
58 jc return_du168
59 _du168_line_02: clr c
60 mov a,#1
61 add a,r7
62 mov r7,a
63 clr a
64 addc a,r6
65 mov r6,a
66
67 return_du168: mov OV,C
68 ret
Previous article:Snake electronic game based on AT89C51 microcontroller
Next article:Unsigned three-byte division by single-byte (51 single-chip microcomputer, assembly source code)
Recommended ReadingLatest update time:2024-11-16 16:03
- Popular Resources
- Popular amplifiers
- MCU C language programming and Proteus simulation technology (Xu Aijun)
- 100 Examples of Microcontroller C Language Applications (with CD-ROM, 3rd Edition) (Wang Huiliang, Wang Dongfeng, Dong Guanqiang)
- Fundamentals and Applications of Single Chip Microcomputers (Edited by Zhang Liguang and Chen Zhongxiao)
- Single chip microcomputer control technology (Li Shuping, Wang Yan, Zhu Yu, Zhang Xiaoyun)
Professor at Beihang University, dedicated to promoting microcontrollers and embedded systems for over 20 years.
- Innolux's intelligent steer-by-wire solution makes cars smarter and safer
- 8051 MCU - Parity Check
- How to efficiently balance the sensitivity of tactile sensing interfaces
- What should I do if the servo motor shakes? What causes the servo motor to shake quickly?
- 【Brushless Motor】Analysis of three-phase BLDC motor and sharing of two popular development boards
- Midea Industrial Technology's subsidiaries Clou Electronics and Hekang New Energy jointly appeared at the Munich Battery Energy Storage Exhibition and Solar Energy Exhibition
- Guoxin Sichen | Application of ferroelectric memory PB85RS2MC in power battery management, with a capacity of 2M
- Analysis of common faults of frequency converter
- In a head-on competition with Qualcomm, what kind of cockpit products has Intel come up with?
- Dalian Rongke's all-vanadium liquid flow battery energy storage equipment industrialization project has entered the sprint stage before production
- Allegro MicroSystems Introduces Advanced Magnetic and Inductive Position Sensing Solutions at Electronica 2024
- Car key in the left hand, liveness detection radar in the right hand, UWB is imperative for cars!
- After a decade of rapid development, domestic CIS has entered the market
- Aegis Dagger Battery + Thor EM-i Super Hybrid, Geely New Energy has thrown out two "king bombs"
- A brief discussion on functional safety - fault, error, and failure
- In the smart car 2.0 cycle, these core industry chains are facing major opportunities!
- The United States and Japan are developing new batteries. CATL faces challenges? How should China's new energy battery industry respond?
- Murata launches high-precision 6-axis inertial sensor for automobiles
- Ford patents pre-charge alarm to help save costs and respond to emergencies
- New real-time microcontroller system from Texas Instruments enables smarter processing in automotive and industrial applications
- Live Review: New Opportunities in UWB Market on June 23
- Questions about DDR3 VTT
- Learn to use WiFi module to remotely burn programs to STM32/GD32 MCU in two minutes
- EEWORLD University Hall----Live Replay: Keysight High-Speed Bus PCIe5.0 Technology Development and Test Sharing
- CMSIS_RTOS_Tutorial self-translated Chinese version
- [Qinheng Trial] Run the ID reading routine
- [Recruitment] Huawei HiSilicon Semiconductor recruits chip R&D positions
- 【ufun learning】Part 2: Initial test demo example
- Problems with temperature acquisition based on stm32f446re
- MCU+MOS tube stepping subdivision drive control solution