Struggling with Multiplication Program (Mult.asm)

classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

Struggling with Multiplication Program (Mult.asm)

MultiplexorMan
I'm feeling a bit let down. I thought I understood Chapter 4 and wrote my Multiplication Program. However, I'm obviously missing something because the program fails at 3 x 1 = 3.

        @R0 //multiplier
        @R1 //multipcand
        @R2 //product
        M=0 //initialize product to zero (0)
(LOOP)
        @R0
        D=M //D=R0 the multiplier
        D=D-1 //D=RO-1
        @END
        D;JLT //if (R0-1)<0 goto END
        @R1
        D=M
        @R2
        M=D+M //R2=R2+R1
        @LOOP
        0;JMP
(END)
        @END
        0;JMP
Reply | Threaded
Open this post in threaded view
|

Re: Struggling with Multiplication Program (Mult.asm)

WBahn
Administrator
Step through your program very carefully.

What should happen to the value of R0 each time through the loop?
Reply | Threaded
Open this post in threaded view
|

Re: Struggling with Multiplication Program (Mult.asm)

MultiplexorMan
It works! It always seems so obvious after the fact. Thank you!
Reply | Threaded
Open this post in threaded view
|

Re: Struggling with Multiplication Program (Mult.asm)

WBahn
Administrator
MultiplexorMan wrote
It works! It always seems so obvious after the fact. Thank you!
Yep, it sure seems to work that way a lot. The good news is that you learn something each time and it makes it that easier to spot similar things in the future.

Congrats.