High-precision division program and its use of 51 single-chip microcomputer

Publisher:传邮万里Latest update time:2011-05-07 Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere
When developing 51 single-chip microcomputer application systems, developers often encounter multi-byte division and reciprocal problems. However, the relevant programs introduced in some current materials are complex, single-function, and low-precision. In the process of developing the GZ93 multi-function program-controlled tester, I designed a 4-byte division by 4-byte program. It has the characteristics of multiple functions, high precision, short duration, and fast running speed. It can be used to find the reciprocal of 4 bytes, the integer of the quotient (the result is 4 bytes), and the decimal part of the quotient (the result is 4 bytes). It can be called twice to find the 8-byte quotient.
I. Usage
1. Find the integer of the quotient
(1) The hexadecimal dividend is sent to the 20 (low) to 23 (high) units in the 51 internal RAM, and the divisor is sent to the 50 (low) to 53 (high) units. The expansion units 24 to 27 are cleared. '
(2) Call the subroutine DIV.
(3) The 20 (low) to 23 (quotient position) units are the quotient to be found, and the 24 to 27 units are the remainder.
2. Find the 8-byte quotient
(1) First find the integer part of the quotient
The method is the same as above, and then the integer quotient of units 20 to 23 is sent to other units for storage.
(2) Find the decimal part of the quotient
. Clear cells 20 to 23; the contents of the other cells remain unchanged; call the DIV subroutine; the decimal quotient is in cells 23 to 20, and the decimal point is
before cell 23.
3. Find the reciprocal
(1) Clear cells 20 to 23 and cells 25 to 27, send 01H to cell 24, and send the divisor to cells 50 (lower order) to 53 (higher order).
(2) Call the DIV subroutine.
(3) The reciprocal is in cells 23 to 20, and the decimal point is before cell 23.
2. Program List
ORG 0500H
DIV: CLR 7EH
MOV R0,#50H
MOV R7,#03H
DV0: MOV A,@R0
INC R0
ORL A,@R0
JNZ DV1
DJNZ R7,DV0
SETB 7EH
SJMP DV8
DV1: MOV R6,#20H
CLRC
DV2: MOV R0,#20H
MOV R7,#08H
DV3: MOV A,@R0
RLC A
MOV @R0,A
INC R0
DJNZ R7,DV3
MOV 0F0H,C
CLR C
MOV R0,#24H
MOV R1,#50H
MOV R7,#04H
DV4: MOV A,@R0
SUB A,@R1
MOV @R0,A
INC R0
INC Rl
DJNZ R7,DV4
JNB 0F0H,DV5
CLR C
SJMP DV6
DV5: JNC DV6
MOV A,24H
ADD A,50H
MOV 24H,A
MOV A,25H
ADDC A,51H
MOV 25H,A
MOV A,26H
ADDC A,52H
MOV 26H,A
MOV A,27H
ADDC A,53H
MOV 27H,A
DV6: CPL C
DJNZ R6,DV2
MOV R0,#20H
MOV R7,#04H
DV7: MOV A,@R0
RLC A
MOV @R0,A
INC R0
DJNZ R7,DV7
DV8: RET
END
Reference address:High-precision division program and its use of 51 single-chip microcomputer

Previous article:51 single chip microcomputer keyboard interface circuit (including source code)
Next article:at89c51 electronic clock circuit diagram and program

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号