Write a program that multiply two _unsigned_ 16bit numbers and the result is 32bit number. First number is in R9:R8, second is in R11:R10 and the result is in R15:R14:R13:R12.

1st type:

First number (R9:R8) shift to right and if Carry is set add second number (R11:R10) to the result. Second number multiply with 2 in every step (shift to left)

2nd type:

use MUL

**************************************** This is what I wrote but it is not working good :( Please help!!

start: ror r8 ror r9 brcs add rol r10 rol r11 jmp start

On 23/11/2006 the venerable snipped-for-privacy@gmail.com etched in runes:

There are several fundamental mistakes, but you will not learn anything by having someone else write your code for you.

How do you know your code is not working? What are the symptoms? Figure out the answers to those two questions and then ask yourself why. It's called 'debugging'.

I'm not asking for the complete solution. I'm asking for the help. What am I doing wrong? Please tell me what that several fundamental mistakes I made. Or point me to some docs.

You are working on 3 digit numbers, but to get the end result you have to add (among other things) the result of 100 * 300 which is 30000

30000 is a *five* digit number.

Try to figure out WHY do you shift the first number right?

Why do you shift the second number left.

You see multiply by 10 above because that is using a decimal system. In your algoritm you use a binary system. What is doing the equivalent of the multiplies by 10 in a binary system.

Your end result is a 32 bit number. In what way does your algorithm affect r15:r14?

If you break down another example into a binary system you get

0x8159 1000000101011001 (second number) x 0x007B x 0000000001111011 (first number) ------------- ---------------------------- 1000000101011001 bit 0 = 1 1000000101011001 bit 1 = 1 0000000000000000 bit 2 = 0 1000000101011001 bit 3 = 1 1000000101011001 bit 4 = 1 1000000101011001 bit 5 = 1 1000000101011001 bit 6 = 1 0000000000000000 bit 7 = 0 0000000000000000 0000000000000000 0000000000000000 0000000000000000 0000000000000000 0000000000000000 0000000000000000 + 0000000000000000 ----------------------------------------------------

The algorithm is simple, you test a bit in the first number and add the value of the second number if the bit is set, and you do not add it if the bit is clear. You do so for each bit in the first number. Testing bit n is asking yourself : Should I add the second number multiplied by 2^n.

ElectronDepot website is not affiliated with any of the manufacturers or service providers discussed here.
All logos and trade names are the property of their respective owners.