Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[bug]: Hardware Simulator still sensitive to order of HDL insturctions #548

Open
1 of 2 tasks
axelkern opened this issue Dec 29, 2024 · 0 comments
Open
1 of 2 tasks
Labels
bug Something isn't working

Comments

@axelkern
Copy link

Tool

Hardware Simulator

Interface

Website (https://nand2tetris.github.io/web-ide)

Contact Details

No response

What happened?

The following code fails the CPU test (in line 17 of CPU.tst). It passes when the register updates are moved to the beginning of the code:


CHIP CPU {
    IN  inM[16],         // M value input  (M = contents of RAM[A])
        instruction[16], // Instruction for execution
        reset;           // Signals whether to re-start the current
                         // program (reset==1) or continue executing
                         // the current program (reset==0).
    OUT outM[16],        // M value output
        writeM,          // Write to M? 
        addressM[15],    // Address in data memory (of M)
        pc[15];          // address of next instruction

    PARTS:
      // loadA, loadD, writeM
      Not(in=instruction[5], out=notD1);
      Nand(a=notD1, b=instruction[15], out=loadA);
      And(a=instruction[4], b=instruction[15], out=loadD);
      And(a=instruction[3], b=instruction[15], out=writeM);
    
      // ALU x=D, y=select A or M
      Mux16(a=outA, b=inM, sel=instruction[12], out=yAlu);
      ALU(x=outD, y=yAlu, zx=instruction[11], nx=instruction[10], zy=instruction[9], ny=instruction[8], f=instruction[7], no=instruction[6], out=outAlu, out=outM, zr=zr, ng=ng);

      // A or C instruction -> select input for A register (Immediate or ALU output)
      Mux16(a[0..14]=instruction[0..14], b=outAlu, sel=instruction[15], out=inA);

      // Jump if C instruction and ((j1 and ng) or (j2 and zr) or (j3 and po))
      Or(a=ng, b=zr, out=ngOrZr); //po=not(ng or zr)
      Not(in=ngOrZr, out=po);
      And(a=instruction[2], b=ng, out=jng);
      And(a=instruction[1], b=zr, out=jzr);
      And(a=instruction[0], b=po, out=jpo);
      Or(a=jng, b=jzr, out=jmp1);
      Or(a=jmp1, b=jpo, out=jmp2);
      And(a=jmp2, b=instruction[15], out=jmp);

      // Update registers
      // !!!
      //  !!! Fails in the web IDE in line 17 of test file. Passes if moved to the beginning of the PARTS section.
      PC(in=outA, load=jmp, inc=true, reset=reset, out[0..14]=pc);
      ARegister(in=inA, load=loadA, out=outA, out[0..14]=addressM);
      DRegister(in=outAlu, load=loadD, out=outD);
}

Additional Comments

No response

Do you want to try to fix this bug?

  • I want to try to add this feature!

Code of Conduct

  • I agree to follow this project's Code of Conduct
@axelkern axelkern added the bug Something isn't working label Dec 29, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant