Unsigned double byte divided by single byte (51 single chip microcomputer, assembly source code)

Publisher:advancement4Latest update time:2017-01-18 Source: eefocusKeywords:Unsigned Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere

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


Keywords:Unsigned Reference address:Unsigned double byte divided by single byte (51 single chip microcomputer, assembly source code)

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

The difference between PIC microcontroller and 51 series microcontroller
There are many types of PIC microcontrollers, which are difficult for beginners to deal with and easy to confuse. The following is a simple classification, which I hope will help beginners learn: Initial 8-bit microcontroller: PIC12C5XXX/16C5X series The PIC16C5X series is the earliest series developed in
[Microcontroller]
STM8L151C8 MCU learning routine (1) - LED flashing
STM8L_1_LED 1.User: Project and main files 2. Hardware: LED, Delay header file 3.STM8L15x_StdPeriph_Driver: STM8 comes with library files 4.Debug: The hex file is stored in the EXE folder 5.Function: LED flashes IAR project code: /** ****************************************************************************** *   
[Microcontroller]
STM8L151C8 MCU learning routine (1) - LED flashing
Design of digital stopwatch based on 51 single chip microcomputer
   In recent years, with the development of science and technology, the application of single-chip microcomputers is constantly going deeper. This paper briefly describes the design of a digital stopwatch based on a single-chip microcomputer. The main feature of this design is that the timing accuracy reaches 0.01 seco
[Microcontroller]
Step-by-step teaching of 51 single chip microcomputer | Lesson 5 Independent keyboard matrix keyboard
Coding keyboard Computer keyboard Non-encoded keyboard (1) Hardware debounce (2) Software debounce Independent keyboard The relationship between lines and first gives the IO port a high level and uses an if to detect the high and low levels of the IO port. If the button is pressed, the IO port is 0 (1&0=0). If it is
[Microcontroller]
Step-by-step teaching of 51 single chip microcomputer | Lesson 5 Independent keyboard matrix keyboard
Design of temperature acquisition and display system based on AT89S51 microcontroller and LM35 temperature sensor
With the rapid development of electronics and sensing technology, temperature measurement and control have been widely used in civil, industrial, aerospace technology and other fields. Small, low-power, cheap, and highly reliable temperature sensors have attracted widespread attention. In actual production, life and o
[Microcontroller]
Design of temperature acquisition and display system based on AT89S51 microcontroller and LM35 temperature sensor
DS18B20 temperature measurement alarm system controlled by 51 single chip microcomputer
Required functions and effects The measurement range of the single-chip DS18B20 temperature measurement system is 0-99.9 degrees Celsius. The upper limit alarm temperature and the lower limit alarm temperature can be set (that is, the buzzer alarms when it is higher than the upper limit value or lower than the lower l
[Microcontroller]
DS18B20 temperature measurement alarm system controlled by 51 single chip microcomputer
Counter based on STC51 microcontroller
Design requirements:# Write a driver for the matrix keyboard Press the corresponding keys respectively. The digital tube will accumulate the corresponding values ​​of the keyboard and display Design Overview: According to the design requirements, the required single-chip microcomputer
[Microcontroller]
Counter based on STC51 microcontroller
Useful information! 8051 microcontroller's inversion method to scan the keyboard
The keyboard scan uses the inversion method to read the keys: first output zero level from the high 4 bits of port P2, and read the keyboard status from the low 4 bits of port P2; then output zero level from the low 4 bits of port P2, and read the keyboard status from the high 4 bits of port P2. Combining the results
[Microcontroller]
Useful information! 8051 microcontroller's inversion method to scan the keyboard
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号