我是Scheme语言的初学者,所以我无法编写一个过程来获取n位数并将其放入ALU中。 ALU应该使用1位ALU构建。算法中的ALU-n过程
这里是1位ALU:
(define ALU1
(lambda (sel a b carry-in)
(multiplexor4 sel
(cons (andgate a b) 0)
(cons (orgate a b) 0)
(cons (xorgate a b) 0)
(multiplexor2 sub
(full-adder a b carry-in)
(full-adder a (notgate b) carry-in)))))
其中,随着多路复用器和全加器,工作原理。
这是我在使用一对夫妇的程序来模拟n位ALU尝试:
(define ALU-helper
(lambda (selection x1 x2 carry-in n)
(if (= n 0)
'()
(ALU1 (selection x1 x2 carry-in)))))
(define ALUn
(lambda (selection x1 x2 n)
(ALU-helper (selection x1 x2 c n))))
而且当它这样做,它应该采取2 n位数字,并将它们添加,或减去等,按照“选择”。这将是输入:
(define x1 '(0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0))
(define x2 '(1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1))
(ALUn 'add x1 x2 32)
而且我运行它时看到由于“选择”参数而发生错误。我确信我只是被所有参数弄糊涂了,但我不确定如何解决这个问题并让ALU工作。我正在使用Dr.Retet程序,即R5RS语言运行此程序。
你会得到什么错误?你应该在你的问题('multiplexor4','multiplexor2','full-adder'等)中发布所有相关的程序,使其成为[SSCCE](http://homepage1.nifty.com/algafield/sscce。 HTML)。 – 2012-04-08 15:01:19