我是Scheme语言的初学者,所以我在编写接受n位数字并将其放入ALU的过程时遇到了问题。ALU应使用1位ALU构建。
下面是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)当我运行它时,我得到了错误,似乎是由于"selection“参数导致的。我确信我只是被所有的参数弄糊涂了,但是我不确定如何解决这个问题并让ALU工作。我正在使用Dr.Sticket程序language R5RS运行此程序。
发布于 2012-04-09 01:08:58
通过在ALU-helper中将参数放在括号内,您要求将ALU1视为一个函数,并且只将一个参数传递给ALU-helper。尝试:
(ALU1 selection x1 x2 carry-in))))在ALUn中对ALU-helper的调用也是如此。
https://stackoverflow.com/questions/10060896
复制相似问题