multiply action on reduced clock cycle

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

multiply action on reduced clock cycle

ysh443
Hi
it looks like the multiplyer test file changes the number of clocks for every diffrent cuple of factors
i notices that because my assembly code fail on test 5
the test is:
set PC 0,
set RAM[0] 3,
set RAM[1] 1;
repeat 120 {
  ticktock;
}

my questions is, why the cycle number is changed for each computation
if we want the product of 2 8bits numbers, isnt the time to compute similar for all cases?

regards
Reply | Threaded
Open this post in threaded view
|

Re: multiply action on reduced clock cycle

cadet1620
Administrator
The algorithm for multiplication described in chapter 4 is simple repeated addition, so the number of iterations required to form the product depends upon the multiplier — the larger the multiplier, the more iterations required.

In chapter 12 you will learn how to write a multiply routine that doesn't become impossibly slow for large multipliers. That routine will take about the same time to multiply any two numbers.

--Mark
Reply | Threaded
Open this post in threaded view
|

Re: multiply action on reduced clock cycle

ysh443
Hi
reading the project_4 contract and purpose, i didnt strickly understood that this is the expected way to
resolve the multiplier problem (i mean iby adding the R0 content R1 times)

instead , i implemented the multiplier in the way i use to multiply decimal numbers using paper and pencil:

12
x
34
---
8(2x4)
+
60(2x30)
+
40(10x4)
+
300(10x30)
---------
408

is my implementetion ok?
on that case, any multiplication should take the same amount of steps (giving same factors size)

regards
Reply | Threaded
Open this post in threaded view
|

Re: multiply action on reduced clock cycle

cadet1620
Administrator
Yes, your implementation is fine. The goal of chapter 4 is to learn the Hack CPU architecture by learning the machine language, so anything that computes multiplication successfully shows that you have learned how memory accesses, conditional jumps, etc. work.

The way you did your multiply, but done in base 2 instead of base 10, is the conventional way to do multiplication in software.

--Mark