虽然我给这个作业打了标签,但它实际上是我自己免费做的一门课程。不管怎么说,这门课的名字叫“从北极星到俄罗斯方块”,我希望这里有人看过或者学过这门课,这样我就能得到一些帮助。我在使用提供的HDL语言构建ALU的阶段。我的问题是我的芯片不能正确编译。尝试设置ALU的输出标志时出现错误。我认为问题是我不能下标任何中间变量,因为当我尝试根据某个随机变量(比如输入标志)将标志设置为true或false时,我不会得到错误。我知道问题不在于我正在尝试使用的芯片,因为我使用的都是内置芯片。
这是到目前为止我的ALU芯片:
/**
* The ALU. Computes a pre-defined set of functions out = f(x,y)
* where x and y are two 16-bit inputs. The function f is selected
* by a set of 6 control bits denoted zx, nx, zy, ny, f, no.
* The ALU operation can be described using the following pseudocode:
* if zx=1 set x = 0 // 16-bit zero constant
* if nx=1 set x = !x // Bit-wise negation
* if zy=1 set y = 0 // 16-bit zero constant
* if ny=1 set y = !y // Bit-wise negation
* if f=1 set out = x + y // Integer 2's complement addition
* else set out = x & y // Bit-wise And
* if no=1 set out = !out // Bit-wise negation
*
* In addition to computing out, the ALU computes two 1-bit outputs:
* if out=0 set zr = 1 else zr = 0 // 16-bit equality comparison
* if out<0 set ng = 1 else ng = 0 // 2's complement comparison
*/
CHIP ALU {
IN // 16-bit inputs:
x[16], y[16],
// Control bits:
zx, // Zero the x input
nx, // Negate the x input
zy, // Zero the y input
ny, // Negate the y input
f, // Function code: 1 for add, 0 for and
no; // Negate the out output
OUT // 16-bit output
out[16],
// ALU output flags
zr, // 1 if out=0, 0 otherwise
ng; // 1 if out<0, 0 otherwise
PARTS:
// Zero the x input
Mux16( a=x, b=false, sel=zx, out=x2 );
// Zero the y input
Mux16( a=y, b=false, sel=zy, out=y2 );
// Negate the x input
Not16( in=x, out=notx );
Mux16( a=x, b=notx, sel=nx, out=x3 );
// Negate the y input
Not16( in=y, out=noty );
Mux16( a=y, b=noty, sel=ny, out=y3 );
// Perform f
Add16( a=x3, b=y3, out=addout );
And16( a=x3, b=y3, out=andout );
Mux16( a=andout, b=addout, sel=f, out=preout );
// Negate the output
Not16( in=preout, out=notpreout );
Mux16( a=preout, b=notpreout, sel=no, out=out );
// zr flag
Or8way( in=out[0..7], out=zr1 ); // PROBLEM SHOWS UP HERE
Or8way( in=out[8..15], out=zr2 );
Or( a=zr1, b=zr2, out=zr );
// ng flag
Not( in=out[15], out=ng );
}
因此,当我试图向Or8Way芯片发送“out”的下标版本时,问题就出现了。我尝试使用与'out‘不同的变量,但遇到了相同的问题。然后我读到你不能下标中间变量。我想也许如果我把中间变量发送给其他芯片,然后那个芯片下标了它,就可以解决这个问题,但它也有同样的错误。不幸的是,我只是想不出一种方法来设置zr和ng标志,而不是下标一些中间变量,所以我真的卡住了!
只是想让你知道,如果我用下面的代码替换有问题的代码行,它将会编译(但不会给出正确的结果,因为我只是使用了一些随机输入):
// zr flag
Not( in=zx, out=zr );
// ng flag
Not( in=zx, out=ng );
有谁有什么想法吗?
hdl:这里是指定如何工作的appendix of the book for the course。具体来看第5节,它谈到了总线,并说:“内部引脚(如上面的v)可能不是下标的”。
编辑:这里是我得到的确切错误:“第68行,无法将gate的输出引脚连接到零件”。然而,错误消息有点令人困惑,因为这似乎不是真正的问题。如果我只是将"Or8way( in=out0..7,out=zr1 );“替换为"Or8way( in=false,out=zr1 );”,它将不会生成此错误,这是导致我在附录中查找并发现out变量无法下标的原因,因为它是作为中间变量派生的。
https://stackoverflow.com/questions/576242
复制相似问题