Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Write a PIC16F877A assembler subroutine called “Mul_8x8” to multiply register Nu

ID: 2246665 • Letter: W

Question

Write a PIC16F877A assembler subroutine called “Mul_8x8” to multiply register Numb1 in memory location 20h, with register Numb2 in memory location 21h. The least significant byte result must be placed in register “AnswL” in memory location 22h. The most significant byte result must be placed in register “AnswH” in memory location 23h. Data in registers Numb1 and Numb2 must remain unchanged after the multiplication. First sketch a flowchart to determine the program structure and then write the firmware source code. Please put flow chart also in answer

Explanation / Answer

To multiply in greater precision you just follow the rule for normal multiplication like you would do on paper. For example multiply 12 times 34 as on paper.

First we multiply 4*2, right that down as 8, then multiply 4 times 1, write that down with the 8 like so:
048

and next we do 3*2=6 and then 3*1=3 and write that as:
360

and next we add the two:
360+048=408

If we were storing these values in 4 bit registers we would store one number in each register, and note we had to add a placeholder of 0 sometimes depending on what digit we were doing.

To extend this to multiple digits, we do the same thing, we just can use bigger registers. For example multiply 1234 times 5678 using registers that hold two digits this time.
We would first multiply 78 times 34, then 78 times 12, and then 56 times 34, then 56 times 12. The place holders this time woudl be two zeros 00 because we are doing two digits at a time. We then add them all the same way, added two digit groups at a time.

This is best done in binary, and the number of bits done at any one time is equal to the largest register available. For your problem it appears that you can use an 8 bit register so you can handle 8 bits at a time.

The catch is that your register has to be able to show the carry when you multiply, or else you have to reduce the number of bits done as one group. For example, doing 4 bits at a time means we might end up with 9 x 9 which would lead to two digits: 81. This would mean we need a register that could hold two digits at a time. In binary, this would be 0x0F times 0x0F which is 0xE1, so we'd need a register that could hold 8 bits even though we are only multiplying two 4 bit binary (or hex) numbers.

For speed you could use a table that has all the entries for digits 0x00 to 0x0F. You then just look up the result and store that in an appropriate place.

If you are working in pure binary, you would just either add the first number (shifted) or not add it, then proceed to the next second number binary digit.
For example to multiply 110 times 101
we add 110, then dont add anything, then add 11000. So it's just shifting and adding.

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote