NB. 8-bit adder and 8-bit ALU using 4 bit adders (circuit model) require'circuits.ijs' fourBitAdder =: monad define 'a3 a2 a1 a0 b3 b2 b1 b0 cin' =. y. t0 =. bitAdder a0 , b0 , cin t1 =. bitAdder a1 , b1 , wireOutput 0 ; t0 t2 =. bitAdder a2 , b2 , wireOutput 0 ; t1 t3 =. bitAdder a3 , b3 , wireOutput 0 ; t2 (wireOutput 0 1 ; t3) , (wireOutput 1 ; t2) , (wireOutput 1 ; t1) , wireOutput 1 ; t0 ) NB. There are too many inputs in an 8-bit adder, so decimal inputs NB. are used and converted, using the following utilities: dtb =: (8#2)&#: btd =: signed_value NB. 8-bit adder eightBitAdder =: monad define 'a b cin' =. dtb y. t0 =. fourBitAdder (4 5 6 7 from a) , (4 5 6 7 from b) , 7 from cin t1 =. fourBitAdder (0 1 2 3 from a) , (0 1 2 3 from b) , wireOutput 0 ; t0 btd (wireOutput 0 1 2 3 4 ; t1) , wireOutput 1 2 3 4 ; t0 ) NB. Next we define an 8-bit ALU using 4 bit adders. NB. The ALU does addition when cin is 0 and NB. subtraction when cin is 1. eightBitALU =: monad define 'a b cin' =. y. a =. dtb a b =. bitXor rank 1 cin,rank 0 dtb b t0 =. fourBitAdder (4 5 6 7 from a) , (4 5 6 7 from b) , cin t1 =. fourBitAdder (0 1 2 3 from a) , (0 1 2 3 from b) , wireOutput 0 ; t0 btd (wireOutput 0 1 2 3 4 ; t1) , wireOutput 1 2 3 4 ; t0 )