;I saw someone online asking for a "four-byte by three-byte" subroutine, so I modified the program I wrote before and posted it below.
;I feel good about it, and think it is the _simplest_ and shortest_ program that can complete this function.
;The program is as follows, haha, sorry for the ugliness.
;===================================================================
ORG 0000H
LJMP START
ORG 0030H ; Main program starts
START:
MOV R7, #05H ; Set a 32-bit dividend
MOV R6, #0F5H ; 05 F5 E0 FFH
MOV R5, #0E0H ; = 99 999 999
MOV R4, #0FFH
; MOV R3, #69H
MOV R2, #98H ; Set a 24-bit divisor
MOV R1, #96H ; 98 96 80H
MOV R0, #80H ; = 10 000 000
CALL DIV_32_24 ;Call the division subroutine
SJMP $ ; Quotient, can be verified by a calculator: 00 00 00 09H
; Remainder: 98 96 7FH = 9 999 999
;********************************************************
;* Four-byte/three-byte unsigned number division program *
;* Already tested *
;****************************************************
; R7R6R5R4 / R2R1R0 --> R7R6R5R4...32H31H30H
;
; Dividend R7R6R5R4, divisor R2R1R0
; Quotient R7R6R5R4, remainder 32H31H30H
; Because the number is large, this program uses: A, B, 33H and 32H 31H 30H
; The protection of these units should be performed in the main program
;-----------------------------------------------------------
DIV_32_24:
CLR A
MOV 30H, A
MOV 31H, A
MOV 32H, A
MOV R3, #32 ;Number of loops
;---------------------------------------------------
CLR C
DIV_LOOP:
CALL SL_R7_R4
CALL SL_32_30
;(32H31H30H <-- R7R6R5R4 <-- C) Shift left one bit
MOV F0, C
;---------------------
CLR C ;IF (32H31H30H >= R2R1R0) 32H31H30H -= R2R1R0;
MOV A, 30H
SUBB A, R0
MOV 33H, A
MOV A, 31H
SUBB A, R1
MOV B, A
MOV A, 32H
SUBB A, R2
JNC DIV_2
JNB F0, CPL_C ;If not enough, don’t save the difference
CPL C
DIV_2:
MOV 30H, 33H
MOV 31H, B
MOV 32H, A
CPL_C:
CPL C
DJNZ R3, DIV_LOOP
;--------------------------------------------------
SL_R7_R4:
MOV A, R4
RLC A
MOV R4, A
MOV A, R5
RLC A
MOV R5, A
MOV A, R6
RLC A
MOV R6, A
MOV A , R7
RLC A
MOV R7, A
RET
;--------------------------
SL_32_30:
MOV A, 30H
RLC A
MOV 30H, A
MOV A, 31H
RLC A
MOV 31H, A
MOV A, 32H
RLC A
MOV 32H, A
RET
;-------------------------------------------------------------
END
;================================================================
Previous article:A simple method to calculate the offset in table lookup instructions
Next article:How to determine the number of bytes in MCS-51 series microcontroller instructions
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
- TI - MCU - MSP430 User Guide 14 -> I2C Communication (eUSCI)
- Analog technology sensor circuit example explanation
- Today at 10:00 am, the live broadcast with prizes: The application of Infineon industrial semiconductors in the motor drive industry has begun!
- EEWORLD University Hall ---- Sharing of temperature measuring gun application solutions based on Lingdong MM32L series low-power MCU
- Microchip live broadcast [How to protect your IP in cloud service connection] has ended
- 51 MCU SPI control four-axis interpolation source program and other information
- Live broadcast at 10:30 this morning [Microchip Security Solutions | Pre-configured Wi-Fi MCUs accelerate product launch and simplify production...
- EEWORLD University Hall----Live Replay: Microchip uses secure elements for accessory authentication
- The C6748 timer is in 32-bit mode
- STM32F103RCT6 Send without permission