Question about M register and A register.

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

Question about M register and A register.

Jorge Bendahan
This post was updated on .
I cannot fully understand the way that M register works and thus can't figure out how Mult.asm should be implemented.

In the book exercise we should implement a two number multiplication (R0 * R1) a store the result in R2

In a high level lang. I would do this:

int Mult(int R0, int R1)
{
    sum = 0;
    count = R0;
    while (count > 0)
    {
        sum = sum + R1;
        count--;
    }

return sum;
}


in ASM:

..
Reply | Threaded
Open this post in threaded view
|

Re: Question about M register and A register.

Jorge Bendahan
This post was updated on .
I still cant pass the test, but this version i think it is little better:

...
Reply | Threaded
Open this post in threaded view
|

Re: Question about M register and A register.

cadet1620
Administrator
I looked at your second version and couldn't find any problems. It runs correctly on my system and passes the test.

First, try deleting Mult.hack and running the assembler again in case the old version is hanging around and being used in the test.

If it still doesn't work, your Mult.tst or Mult.cmp might have been corrupted—try these versions:

Mult.cmp
Mult.tst

--Mark

[Also, please edit your second post to remove the code sample since it is complete working code.]

Reply | Threaded
Open this post in threaded view
|

Re: Question about M register and A register.

Jorge Bendahan
You're right. it works..