Problem to divide two 16 bit numbers in 8051 series microcontrollers

In summary, the conversation discusses a project involving coding in the 8051 series, specifically division of two 16-bit unsigned integers and how to store the quotient and remainder in the internal memory. The participants share their understanding of binary division and suggest resources for learning the 8051 instruction set and assembly language programming. They also suggest trying simpler projects before attempting multi-byte division. One participant recommends watching educational videos on computer operations.
  • #1
Stonestreecty
20
3
TL;DR Summary
Code in 8051 microcontroller Problem: How to understand "Division of two 16 bit unsigned integers being in the internal memory, quotient and remainder should be stored".
Hi all,
I have a project to code in 8051 series, DS80C320-ECG (data source as reference): "Division of two 16 bit unsigned integers being in the internal memory, quotient and remainder should be stored".
DS80C320-ECG Image.jpg

I find a way to do it but there is a part of the program that i don't understand, I attach it.
I've noted which part i don't understand. By "don't understand", means that I'm not understanding why do we have to do all those calculations to find the quotient and the remainder.

Is there anyone have ideas of it? Thanks in advance.
 
Technology news on Phys.org
  • #2
Is this assignment homework?
Do you understand long division?
https://en.wikipedia.org/wiki/Long_division
You can extend that to binary.
Do a trial subtract, record 1 if it stayed positive or revert and shift if trial was negative. Do that trial subtract 16 times, as you shift it to the right.

I see no code attachment.
 
  • #3
Baluncore said:
Is this assignment homework?
Do you understand long division?
https://en.wikipedia.org/wiki/Long_division
You can extend that to binary.
Do a trial subtract, record 1 if it stayed positive or revert and shift if trial was negative. Do that trial subtract 16 times, as you shift it to the right.

I see no code attachment.
yep...the basic principle of binary division in a computer is similar to one of the "long division" methods using pencil and paper.
 

Attachments

  • 16 bit div.txt
    3 KB · Views: 366
  • #4
You did not say if it was homework.

I think you should follow the algorithm on a sheet of paper in binary, then code it in assy. You will not learn much by copying existing code.

What do you not understand?
 
  • #5
yep, it is a good learning experience as a beginner, I just want to make attempt at understanding the program.
 
  • #8
I would also like to suggest that you try the videos produced by Ben Eater. He can teach you both the hardware and software side of computer operations, including micro code, software, interfacing, and even building a 6502 computer from scratch if you want to go that far.

https://www.youtube.com/user/eaterbc
 

FAQ: Problem to divide two 16 bit numbers in 8051 series microcontrollers

How do I divide two 16 bit numbers in 8051 series microcontrollers?

In order to divide two 16 bit numbers in 8051 series microcontrollers, you will need to use a specific instruction called DIV. This instruction takes the first number in the accumulator and divides it by the second number, storing the quotient in the accumulator and the remainder in register B.

What are the limitations of dividing two 16 bit numbers in 8051 series microcontrollers?

One limitation of dividing two 16 bit numbers in 8051 series microcontrollers is that the numbers must be unsigned. This means that the numbers cannot have a negative sign and must be within the range of 0 to 65,535.

What happens if the result of the division exceeds the 16 bit limit?

If the result of the division exceeds the 16 bit limit, the quotient will be truncated and only the lower 16 bits will be stored in the accumulator. The remainder will still be stored in register B.

How do I check for divide by zero errors in 8051 series microcontrollers?

In 8051 series microcontrollers, the DIV instruction does not have the ability to check for divide by zero errors. It is the programmer's responsibility to ensure that the second number is not zero before performing the division operation.

Are there any alternative methods for dividing two 16 bit numbers in 8051 series microcontrollers?

Yes, there are alternative methods for dividing two 16 bit numbers in 8051 series microcontrollers. One method is to use a library routine that implements the long division algorithm. Another method is to split the 16 bit numbers into two 8 bit numbers and perform the division using the DIV instruction for 8 bit numbers.

Similar threads

Replies
32
Views
2K
Replies
4
Views
4K
Replies
8
Views
2K
Replies
2
Views
2K
Replies
1
Views
1K
Replies
6
Views
2K
Replies
1
Views
2K
Back
Top