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 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 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 257 of CO&D (2ed). NB. Assume 32-bit Multiplier and 32-bit Multiplicand NB. mult3 uses alu_32. mult3 =: monad define ('multiplicand' ; 'multiplier') =. y. product=. (32#0),multiplier count=.32 while. 0 not_equal count do. control =. last product if. control do. product =. (alu_32 (32 take product) ; multiplicand) , 32 drop product end. product =. 0 , _1 drop product count =. <: count end. product ) NB. a test product of 3 * 2 mult3 ((30#0), 1 1); (30#0),1 0 NB. A Tracing Model of Multiplier Hardware, Page 257 of CO&D (2ed). NB. Assume 32-bit Multiplier and 32-bit Multiplicand NB. mult3 uses alu_32. traced_mult3 =: monad define ('multiplicand' ; 'multiplier') =. y. display 'start-product';product=. (32#0),multiplier count=.32 while. 0 not_equal count do. control =. last product if. control do. display'alu-product';product =. (alu_32 (32 take product) ; multiplicand) , 32 drop product end. display'shift-product';product =. 0 , _1 drop product count =. <: count end. product ) NB. a test product of 3 * 2 traced_mult3 ((30#0), 1 1); (30#0),1 0