Hi all,
i am trying to write an iterative multiplexer and having some trouble in getting started,
in this exercise i need to use an adder (with no consideration for the carry).
and use a register i have write as a component .
and a counter.
so here is a few question i hope will help me:
1. Suppose i have A and B numbers. should i save them in registers, and run a loop B times (using the counter) and every iteration add A <= A+A ?
In general, that is never the best way to go. It is easier to do in the same way you would do it by hand. eg:
23 * 12 = 23*10 + 23*2 = 230 + 46 = 276
1010 * 1100 = 1010*1000 + 1010*100 + 1010*0 + 1010*0 = 1010000 + 101000 = 1111000
in a loop, a = 1010, b = 1100, s = 0 (output), n = 0 (index)
s = s + a * 2^n if b == 1
so:
s=0. n=0. b(0) = 0. result -- s = 0
s=0. n=1. b(1) = 0. result -- s = 0
s=0. n=2. b(2) = 1. result -- s = 1010*2^2 = 101000
s=101000. n = 3. b(3) = 1. result -- s = 1111000
thus the multiplication runs much faster -- the number of iterations scales with the width of a (or b).