Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 133673
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T06:28:31+00:00 2026-05-11T06:28:31+00:00

Although I tagged this homework, it is actually for a course which I am

  • 0

Although I tagged this homework, it is actually for a course which I am doing on my own for free. Anyway, the course is called ‘From Nand to Tetris’ and I’m hoping someone here has seen or taken the course so I can get some help. I am at the stage where I am building the ALU with the supplied hdl language. My problem is that I can’t get my chip to compile properly. I am getting errors when I try to set the output flags for the ALU. I believe the problem is that I can’t subscript any intermediate variable, since when I just try setting the flags to true or false based on some random variable (say an input flag), I do not get the errors. I know the problem is not with the chips I am trying to use since I am using all builtin chips.

Here is my ALU chip so far:

/**  * 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 );  } 

So the problem shows up when I am trying to send a subscripted version of ‘out’ to the Or8Way chip. I’ve tried using a different variable than ‘out’, but with the same problem. Then I read that you are not able to subscript intermediate variables. I thought maybe if I sent the intermediate variable to some other chip, and that chip subscripted it, it would solve the problem, but it has the same error. Unfortunately I just can’t think of a way to set the zr and ng flags without subscripting some intermediate variable, so I’m really stuck!

Just so you know, if I replace the problematic lines with the following, it will compile (but not give the right results since I’m just using some random input):

// zr flag Not( in=zx, out=zr );  // ng flag Not( in=zx, out=ng ); 

Anyone have any ideas?

Edit: Here is the appendix of the book for the course which specifies how the hdl works. Specifically look at section 5 which talks about buses and says: ‘An internal pin (like v above) may not be subscripted’.

Edit: Here is the exact error I get: ‘Line 68, Can’t connect gate’s output pin to part’. The error message is sort of confusing though, since that does not seem to be the actual problem. If I just replace ‘Or8way( in=out[0..7], out=zr1 );’ with ‘Or8way( in=false, out=zr1 );’ it will not generate this error, which is what lead me to look up in the appendix and find that the out variable, since it was derived as intermediate, could not be subscripted.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. 2026-05-11T06:28:31+00:00Added an answer on May 11, 2026 at 6:28 am

    The solution as Pax suggested was to use an intermediate variable as input to another chip, such as Or16Way. Here is the code after I fixed the problem and debugged:

    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=x2, out=notx ); Mux16( a=x2, b=notx, sel=nx, out=x3 );  // Negate the y input Not16( in=y2, out=noty ); Mux16( a=y2, 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=preout2 );  // zr flag Or16Way( in=preout2, out=notzr ); Not( in=notzr, out=zr );  // ng flag And16( a=preout2, b=true, out[15]=ng );  // Get final output And16( a=preout2, b=preout2, out=out ); } 
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 78k
  • Answers 78k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • added an answer Other than just doing the import via SSIS or some… May 11, 2026 at 3:40 pm
  • added an answer One built into your GUI can be very helpful (I… May 11, 2026 at 3:40 pm
  • added an answer Well, you can just count how many times you shift… May 11, 2026 at 3:40 pm

Related Questions

We have many projects that use a common base of shared components (dlls). Currently
Although I'm specifically interested in web application information, I would also be somewhat curious
Although I don't have an iPhone to test this out, my colleague told me
Although I do understand the serious implications of playing with this function (or at

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.