Multi-byte unsigned binary number division microcontroller assembly program example

Publisher:muhaoying2017Latest update time:2017-10-15 Source: eefocus Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere

Example: Divide (R2R3R4R5) by (R6R7), the quotient is sent to (R4R5), and the remainder is sent to (R2R3). Manual calculation method: 

1) Align the divisor from the high bit of the dividend and compare. 

2) If the former is greater than or equal to the latter, the quotient is 1, and the dividend is subtracted from the divisor to form a partial remainder. If the former is less than the latter, the quotient is 0. 

3) The partial remainder is shifted left by one bit, and the quotient is also shifted left by one bit. 

4) If the entire remainder is less than the divisor, exit. 

5) Compare the partial remainder with the divisor from the high bit 

6) Go to step 2). 

If the high 16 bits of the dividend are greater than or equal to the divisor, overflow occurs. 

NDIV: MOV A, R3 

CLR C 

SUBB A, R7 ; first compare whether overflow occurs 

MOV A, R2 

SUBB A, R6 

JNC NDVE1 ; overflow 

MOV B, #16 ; no overflow, 16 bits 

NDVL1: CLR C 

MOV A, R5 

RLC A 

MOV R5, A 

MOV A, R4 

RLC A 

MOV R4, A ; the dividend is shifted left by one bit, and the quotient is also shifted left by one bit 

MOV A, R3 

RLC A 

MOV R3, A 

MOV A, R2 

RLC A 

MOV R2, A 

MOV F0, C ; save the highest bit shifted out 

CLR C 

MOV A, R3 

SUBB A, R7 ; compare the partial remainder with the divisor 

MOV R1, A 

MOV A, R2 

SUBB A, R6 

JB F0, NDVM1 ; if the last highest bit = 1, then the quotient bit = 1 

JC NDVD1 ; if the partial remainder is less than the divisor, then the quotient bit = 0 

NDVM1: MOV R2, A 

MOV A, R1 

MOV R3, A ; return subtraction result 

INC R5 ; quotient = 1 

NDVD1: DJNZ B, NDVL1 ; loop 16 times 

CLR F0 

RET 

NDVE1: SETB F0 ; overflow flag 

RET 

Reference address:Multi-byte unsigned binary number division microcontroller assembly program example

Previous article:Improved bubble sorting microcontroller assembly language programming example
Next article:An example of a program to multiply two double-byte unsigned numbers in a single-chip microcomputer

Recommended ReadingLatest update time:2024-11-17 05:31

Simulation of Four-way Answering Machine Based on 51 Single-chip Microcomputer
When the host presses the start button, a 60-second countdown begins and the contestants begin to answer. Once a contestant answers, the answers of other contestants will be invalid. And the countdown stops after the contestant answers. Since I did not set a new round button, if you need to use a new round of answ
[Microcontroller]
Simulation of Four-way Answering Machine Based on 51 Single-chip Microcomputer
Design and production of DDS signal source based on ATmega16 microcontroller
1. Basic working principle of DDS The basic principle of DDS is to use the Nyquist sampling theorem to generate waveforms through a table lookup method. There are many types of DDS structures, and its basic circuit principle can be represented by the figure below. It mainly includes a phase register, a phase full ad
[Microcontroller]
Design and production of DDS signal source based on ATmega16 microcontroller
Eight steps to quickly master MCU learning
   Learning to use a microcontroller means understanding the microcontroller hardware structure and the application of internal resources, learning how to initialize various functions in assembly or C language, and how to compile programs to implement various functions.   Step 1: Use of Digital I/O   By using button
[Microcontroller]
Intelligent invisible anti-theft net for balcony based on single chip microcomputer
1 Introduction At present, in many cities in China, for the purpose of anti-theft, metal anti-theft nets are basically installed on balconies and windowsills in residential buildings, which consumes a lot of metal materials and affects the appearance of the city. At the same time, if the maintenance is not
[Microcontroller]
Intelligent invisible anti-theft net for balcony based on single chip microcomputer
Stopwatch timing function (simulation) single chip computer program
The following simulation effect diagram can be made according to the above circuit /** //Imitate the stopwatch timing function, and the independent button can control the "pause/move" of the timing numbers. (The program does not consider the timing accuracy control) /*P2.2~P2.4 are connected to th
[Microcontroller]
Stopwatch timing function (simulation) single chip computer program
Comprehensive analysis of the characteristics and shortcomings of PIC microcontrollers
According to the survey, PIC microcontroller is one of the most used hardware by relevant personnel. Therefore, all beginners need to have a certain understanding of PIC microcontroller. To this end, this article brings you three parts: 1. Introduction to PIC microcontroller, 2. Characteristics of PIC microcontroller,
[Microcontroller]
Comprehensive analysis of the characteristics and shortcomings of PIC microcontrollers
A method to realize LCD multi-level menu in single chip C language
0 Preface       Due to the structure and modularity of C language, programs written in C language are easy to read and maintain, and have good portability. This paper introduces a method of implementing LCD multi-level menus in C language, which has been successfully applied to coal mine safety monitoring equipment.
[Microcontroller]
Design of STC15F104E STC microcontroller automatic download system
Introduction STC microcontroller is a series of 51 microcontrollers developed by China's Hongjing Company. STC microcontroller is based on the traditional 8051 microcontroller. After technical improvement and resource expansion, it has the advantages of rich on-chip resources, fast computing speed and low price.
[Microcontroller]
Design of STC15F104E STC microcontroller automatic download system
Latest Microcontroller Articles
  • Download from the Internet--ARM Getting Started Notes
    A brief introduction: From today on, the ARM notebook of the rookie is open, and it can be regarded as a place to store these notes. Why publish it? Maybe you are interested in it. In fact, the reason for these notes is ...
  • Learn ARM development(22)
    Turning off and on interrupts Interrupts are an efficient dialogue mechanism, but sometimes you don't want to interrupt the program while it is running. For example, when you are printing something, the program suddenly interrupts and another ...
  • Learn ARM development(21)
    First, declare the task pointer, because it will be used later. Task pointer volatile TASK_TCB* volatile g_pCurrentTask = NULL;volatile TASK_TCB* vol ...
  • Learn ARM development(20)
    With the previous Tick interrupt, the basic task switching conditions are ready. However, this "easterly" is also difficult to understand. Only through continuous practice can we understand it. ...
  • Learn ARM development(19)
    After many days of hard work, I finally got the interrupt working. But in order to allow RTOS to use timer interrupts, what kind of interrupts can be implemented in S3C44B0? There are two methods in S3C44B0. ...
  • Learn ARM development(14)
  • Learn ARM development(15)
  • Learn ARM development(16)
  • Learn ARM development(17)
Change More Related Popular Components

EEWorld
subscription
account

EEWorld
service
account

Automotive
development
circle

About Us Customer Service Contact Information Datasheet Sitemap LatestNews


Room 1530, 15th Floor, Building B, No.18 Zhongguancun Street, Haidian District, Beijing, Postal Code: 100190 China Telephone: 008610 8235 0740

Copyright © 2005-2024 EEWORLD.com.cn, Inc. All rights reserved 京ICP证060456号 京ICP备10001474号-1 电信业务审批[2006]字第258号函 京公网安备 11010802033920号