この宿題にタグを付けましたが、実際には無料で自分でやっているコース用です。とにかく、このコースは「ナンドからテトリスへ」と呼ばれており、誰かがこのコースを見たり受講したりしているので、助けが得られることを願っています. 提供された 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 );
}
そのため、'out' の添字付きバージョンを Or8Way チップに送信しようとすると、問題が発生します。「out」とは異なる変数を使用してみましたが、同じ問題があります。次に、中間変数に添字を付けることができないことを読みました。中間変数を他のチップに送信し、そのチップに添字を付ければ問題は解決するのではないかと思いましたが、同じエラーが発生しました。残念ながら、中間変数に添え字を付けずに zr フラグと ng フラグを設定する方法が思い浮かびません。
ご存知のように、問題のある行を次のように置き換えると、コンパイルされます (ただし、ランダムな入力を使用しているだけなので、正しい結果は得られません)。
// zr flag
Not( in=zx, out=zr );
// ng flag
Not( in=zx, out=ng );
誰にもアイデアはありますか?
編集:これは、hdlの仕組みを指定するコースの本の付録です。具体的には、バスについて説明しているセクション 5 を見てください。
編集:ここに私が得る正確なエラーがあります:「68行目、ゲートの出力ピンをパーツに接続できません」。ただし、実際の問題ではないように見えるため、エラーメッセージはやや混乱しています。「Or8way( in=out[0..7], out=zr1 );」を置き換えるだけなら 「Or8way( in=false, out=zr1 );」で このエラーは生成されないため、付録を調べたところ、 out 変数は中間として導出されたため、添え字を付けることができませんでした。