admin管理员组文章数量:1122846
I have to design this in nand2tetris and I created a new folder on my desktop and did this
CHIP CarrySelectAdder16 {
IN a[16], b[16], cin; // 16-bit inputs and 1-bit initial carry-in
OUT sum[16], cout; // 16-bit sum and 1-bit carry-out
PARTS:
// Block 1: 2-bit addition
CarrySelectBlock2(a=a[0..1], b=b[0..1], cin=cin, sum=sum[0..1], cout=carry1);
// Block 2: 2-bit addition
CarrySelectBlock2(a=a[2..3], b=b[2..3], cin=carry1, sum=sum[2..3], cout=carry2);
// Block 3: 3-bit addition
CarrySelectBlock3(a=a[4..6], b=b[4..6], cin=carry2, sum=sum[4..6], cout=carry3);
// Block 4: 4-bit addition
CarrySelectBlock4(a=a[7..10], b=b[7..10], cin=carry3, sum=sum[7..10], cout=carry4);
// Block 5: 5-bit addition
CarrySelectBlock5(a=a[11..15], b=b[11..15], cin=carry4, sum=sum[11..15], cout=cout);
}
This is the code i sued to calculate this I wrote Carryselectblock like this
CHIP CarrySelectBlock2 {
IN a[2], b[2], cin; // Two 2-bit input buses and carry-in
OUT sum[2], carry; // 2-bit sum output and carry-out
PARTS:
// First adder with cin = 0
RippleCarryAdder2(a=a, b=b, cin=false, sum=sum0, carry=carry0);
// Second adder with cin = 1
RippleCarryAdder2(a=a, b=b, cin=true, sum=sum1, carry=carry1);
// Muxes to select the correct sum bits based on cin
Mux(a=sum0[0], b=sum1[0], sel=cin, out=sum[0]);
Mux(a=sum0[1], b=sum1[1], sel=cin, out=sum[1]);
// Mux to select the correct carry based on cin
Mux(a=carry0, b=carry1, sel=cin, out=carry);
}
The error I'm getting is that I cannot use a sub bus of a internal node
I have to design this in nand2tetris and I created a new folder on my desktop and did this
CHIP CarrySelectAdder16 {
IN a[16], b[16], cin; // 16-bit inputs and 1-bit initial carry-in
OUT sum[16], cout; // 16-bit sum and 1-bit carry-out
PARTS:
// Block 1: 2-bit addition
CarrySelectBlock2(a=a[0..1], b=b[0..1], cin=cin, sum=sum[0..1], cout=carry1);
// Block 2: 2-bit addition
CarrySelectBlock2(a=a[2..3], b=b[2..3], cin=carry1, sum=sum[2..3], cout=carry2);
// Block 3: 3-bit addition
CarrySelectBlock3(a=a[4..6], b=b[4..6], cin=carry2, sum=sum[4..6], cout=carry3);
// Block 4: 4-bit addition
CarrySelectBlock4(a=a[7..10], b=b[7..10], cin=carry3, sum=sum[7..10], cout=carry4);
// Block 5: 5-bit addition
CarrySelectBlock5(a=a[11..15], b=b[11..15], cin=carry4, sum=sum[11..15], cout=cout);
}
This is the code i sued to calculate this I wrote Carryselectblock like this
CHIP CarrySelectBlock2 {
IN a[2], b[2], cin; // Two 2-bit input buses and carry-in
OUT sum[2], carry; // 2-bit sum output and carry-out
PARTS:
// First adder with cin = 0
RippleCarryAdder2(a=a, b=b, cin=false, sum=sum0, carry=carry0);
// Second adder with cin = 1
RippleCarryAdder2(a=a, b=b, cin=true, sum=sum1, carry=carry1);
// Muxes to select the correct sum bits based on cin
Mux(a=sum0[0], b=sum1[0], sel=cin, out=sum[0]);
Mux(a=sum0[1], b=sum1[1], sel=cin, out=sum[1]);
// Mux to select the correct carry based on cin
Mux(a=carry0, b=carry1, sel=cin, out=carry);
}
The error I'm getting is that I cannot use a sub bus of a internal node
Share Improve this question asked Nov 21, 2024 at 16:51 HElpHElp 314 bronze badges1 Answer
Reset to default 1In future, please specify what line in what file is generating the error.
However, the error message is explicitly telling you what the problem is -- you cannot use a subset of an internal bus as an input (ie: a=sum0[0] is not permitted).
You will have to redesign your chips to avoid this limitation.
Please refer to the book appendixes for more details on the format and limitations of NAND2Tetris HDL.
本文标签:
版权声明:本文标题:nand2tetris - Design and implement 16-bit carry-select adder with variable size (block sizes of 2-2-3-4-5) - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1736308712a1933761.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论