[CSCI2321] Corrected mult.ijs file which works with circuit or
non-circuit alu_32
John Howland
jhowland at ariel.cs.trinity.edu
Wed Feb 22 10:44:44 CST 2006
The attachment says it all.
_______________________________________________________________
John E. Howland url: http://www.cs.trinity.edu/~jhowland/
Computer Science email: jhowland at ariel.cs.trinity.edu
Trinity University voice: (210) 999-7364
One Trinity Place fax: (210) 999-7477
San Antonio, Texas 78212-7200
-------------- next part --------------
NB. Models of Multiplication discussed in Section 3.4 of
NB. Computer Organization & Design by Patterson and Hennessy
NB. Binary To Decimal
btd =: monad define
digits =. # y.
if. 1 = 1 take y.
do. ((digits copy 2) base x: y. ) - 2^ x: digits
else. (digits copy 2) base x: y.
end.
)
NB. Non-circuit based 64-bit ALU
alu_64 =: monad define
NB. a and b are each 64-bit summands
NB. the result is a 64-bit sum
'a b' =. y.
(64#2) rep (base x: a) + base x: b
)
NB. Some alu_64 tests.
a =: (63#1),0
b=: (62#0), 1 0
alu_64 a;b
c=:64#1
alu_64 b;c
NB. Note that decimal args may be used with alu_64
alu_64 3 4
alu_64 100 ; 28
base alu_64 100 ; 28
NB. Model of Multiplier Hardware, Page 177 of CO&D.
NB. Assume 32-bit Multiplier and 64-bit Multiplicand
NB. mult1 uses alu_64.
mult1 =: monad define
('multiplicand' ; 'multiplier') =. y.
product=. 64#0
count=. 32
while. 0 not_equal count
do. control =. last multiplier
if. control
do. product =. alu_64 product ; multiplicand
end.
multiplicand =. (1 drop multiplicand),0
multiplier =. 0 , _1 drop multiplier
count =. <: count
end.
product
)
NB. a test product of 3 * 2
mult1 ((62#0), 1 1); (30#0),1 0
NB. what about negative values
mult1 ((62#1), 0 1); (30#0),1 0
mult1 ((62#1), 0 1); (30#1),1 0
NB. A Tracing Model of Multiplier Hardware, Page 177 of CO&D.
NB. Assume 32-bit Multiplier and 64-bit Multiplicand
NB. traced_mult1 uses alu_64.
traced_mult1 =: monad define
('multiplicand' ; 'multiplier') =. y.
display 'product';product=. 64#0
count=. 32
while. 0 not_equal count
do. control =. last multiplier
if. control
do. display 'alu-product';product =. alu_64 product ; multiplicand
end.
display 'multiplicand';multiplicand =. (1 drop multiplicand),0
display 'multiplier';multiplier =. 0 , _1 drop multiplier
count =. <: count
end.
product
)
NB. a test product of 3 * 2
NB. traced_mult1 ((62#0), 1 1); (30#0),1 0
NB. what about negative values
NB. traced_mult1 ((62#1), 0 1); (30#0),1 0
NB. traced_mult1 ((62#1), 0 1); (30#1),1 0
NB. Notice that the above multiplier is more closely based
NB. on the flow chart of Page 178. We modify the model to
NB. resemble, more closely, the circuit diagram of Page 177
alu_64m =: monad define
NB. product and b are each 64-bit summands
NB. the result is a 64-bit sum
('b' ; 'control') =. y.
if. control
do. product =: (64#2) rep (base x: product) + base x: b
end.
)
NB. A modified Model of Multiplier Hardware, Page 177 of CO&D.
NB. Assume 32-bit Multiplier and 64-bit Multiplicand
NB. mult1m uses alu_64m.
mult1m =: monad define
('multiplicand' ; 'multiplier') =. y.
product=: 64#0
count =. 32
while. 0 not_equal count
do. control =. last multiplier
alu_64m multiplicand ; control
multiplicand =. (1 drop multiplicand),0
multiplier =. 0 , _1 drop multiplier
count =. <: count
end.
product
)
NB. a test product of 3 * 2
mult1m ((62#0), 1 1); (30#0),1 0
NB. what about negative values
mult1m ((62#1), 0 1); (30#0),1 0
mult1m ((62#1), 0 1); (30#1),1 0
NB. A traced version of the modified alu_64.
NB. Notice that the above multiplier is more closely based
NB. on the flow chart of Page 178. We modify the model to
NB. resemble, more closely, the circuit diagram of Page 177
traced_alu_64m =: monad define
NB. product and b are each 64-bit summands
NB. the result is a 64-bit sum
('b' ; 'control') =. y.
if. control
do. display 'alu-product';product =: (64#2) rep (base x: product) + base x: b
end.
)
NB. A traced version of the modified multiplier.
NB. A modified Model of Multiplier Hardware, Page 177 of CO&D.
NB. Assume 32-bit Multiplier and 64-bit Multiplicand
NB. traced_mult1m uses traced_alu_64m.
traced_mult1m =: monad define
('multiplicand' ; 'multiplier') =. y.
display 'product';product=: 64#0
count =. 32
while. 0 not_equal count
do. control =. last multiplier
traced_alu_64m multiplicand ; control
display 'multiplicand';multiplicand =. (1 drop multiplicand),0
display 'multiplier';multiplier =. 0 , _1 drop multiplier
count =. <: count
end.
product
)
NB. a test product of 3 * 2
NB. traced_mult1m ((62#0), 1 1); (30#0),1 0
NB. what about negative values
NB. traced_mult1m ((62#1), 0 1); (30#0),1 0
NB. traced_mult1m ((62#1), 0 1); (30#1),1 0
NB. Non-circuit based 32-bit ALU
alu_32 =: monad define
NB. a and b are each 32-bit summands
NB. the result is a 32-bit sum
('a' ; 'b') =. y.
(32#2) rep (base x: a) + base x: b
)
NB. Some alu_32 tests.
a =: (31#1),0
b=: (30#0), 1 0
alu_32 a;b
c =: 32#1
alu_32 b;c
NB. Note that decimal args may be used with alu_32
alu_32 3 4
alu_32 100 ; 28
base alu_32 100 ; 28
NB. Model of Multiplier Hardware, Page 179 of CO&D.
NB. Assume 32-bit Multiplier and 32-bit Multiplicand
NB. mult2 uses alu_32.
mult2 =: monad define
('multiplicand' ; 'multiplier') =. y.
product=. 64#0
count =. 32
while. 0 not_equal count
do. control =. last multiplier
if. control
do. product =. (alu_32 (32 take product) ; multiplicand) , 32 drop product
end.
product =. 0 , _1 drop product
multiplier =. 0 , _1 drop multiplier
count =. <: count
end.
product
)
NB. a test product of 3 * 2
mult2 ((30#0), 1 1); (30#0),1 0
NB. what about negative values
mult2 ((30#1), 0 1); (30#0),1 0
mult2 ((30#1), 0 1); (30#1),1 0
NB. A Tracing Model of Multiplier Hardware, Page 179 of CO&D.
NB. Assume 32-bit Multiplier and 32-bit Multiplicand
NB. traced_mult2 uses alu_32.
traced_mult2 =: monad define
('multiplicand' ; 'multiplier') =. y.
display 'product';product=. 64#0
count =. 32
while. 0 not_equal count
do. control =. last multiplier
if. control
do. display 'alu-product';product =. (alu_32 (32 take product) ; multiplicand) , 32 drop product
end.
display 'product';product =. 0 , _1 drop product
display 'multiplier';multiplier =. 0 , _1 drop multiplier
count =. <: count
end.
product
)
NB. a test product of 3 * 2
NB. traced_mult2 ((30#0), 1 1); (30#0),1 0
NB. what about negative values
NB. traced_mult2 ((30#1), 0 1); (30#0),1 0
NB. traced_mult2 ((30#1), 0 1); (30#1),1 0
NB. A modified version of the alu_32 which more closely
NB. resembles the ciruit diagram of Page 179 of CO&D.
NB. Non-circuit based 32-bit ALU
alu_32m =: monad define
NB. product and b are each 32-bit summands
NB. the result is a 32-bit sum
('b' ; 'control') =. y.
if. control
do. product =: ((32#2) rep (base x: 32 take product) + base x: b) , 32 drop product
end.
)
NB. Modified model of Multiplier Hardware, Page 179 of CO&D.
NB. Assume 32-bit Multiplier and 32-bit Multiplicand
NB. mult2m uses alu_32m.
mult2m =: monad define
('multiplicand' ; 'multiplier') =. y.
product=: 64#0
count =. 32
while. 0 not_equal count
do. control =. last multiplier
alu_32m multiplicand ; control
product =: 0 , _1 drop product
multiplier =. 0 , _1 drop multiplier
count =. <: count
end.
product
)
NB. a test product of 3 * 2
mult2m ((30#0), 1 1); (30#0),1 0
NB. what about negative values
mult2m ((30#1), 0 1); (30#0),1 0
mult2m ((30#1), 0 1); (30#1),1 0
NB. A traced version of alu_32m
NB. A modified version of the alu_32 which more closely
NB. resembles the ciruit diagram of Page 179 of CO&D.
NB. Non-circuit based 32-bit ALU
traced_alu_32m =: monad define
NB. product and b are each 32-bit summands
NB. the result is a 32-bit sum
('b' ; 'control') =. y.
if. control
do. display 'alu-product';product =: ((32#2) rep (base x: 32 take product) + base x: b) , 32 drop product
end.
)
NB. A traced version of mult2m
NB. Modified model of Multiplier Hardware, Page 179 of CO&D.
NB. Assume 32-bit Multiplier and 32-bit Multiplicand
NB. mult2m uses alu_32m.
traced_mult2m =: monad define
('multiplicand' ; 'multiplier') =. y.
display 'product';product=: 64#0
count =. 32
while. 0 not_equal count
do. control =. last multiplier
traced_alu_32m multiplicand ; control
display 'product';product =: 0 , _1 drop product
display 'multiplier';multiplier =. 0 , _1 drop multiplier
count =. <: count
end.
product
)
NB. a test product of 3 * 2
NB. traced_mult2m ((30#0), 1 1); (30#0),1 0
NB. what about negative values
NB. traced_mult2m ((30#1), 0 1); (30#0),1 0
NB. traced_mult2m ((30#1), 0 1); (30#1),1 0
More information about the CSCI2321
mailing list