Please help with the ALU code bug.

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Please help with the ALU code bug.

rajat
This post was updated on .
// This file is part of www.nand2tetris.org
// and the book "The Elements of Computing Systems"
// by Nisan and Schocken, MIT Press.
// File name: projects/02/ALU.hdl

CHIP ALU {
    IN  
        x[16], y[16],  // 16-bit inputs        
        zx, // zero the x input?
     
  nx, // negate the x input?
        zy, // zero the y input?
        ny, // negate the y input?
        f,  // compute out = x + y (if 1) or x & y (if 0)
        no; // negate the out output?

    OUT
        out[16], // 16-bit output
         zr,ng;// 1 if (out < 0),  0 otherwise

    PARTS:
   // Put you code here:

}
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Please help with the ALU code bug.

cadet1620
Administrator
rajat wrote
Not16(in=zeroornotx,out=negativexpartial);
Inc16(in=negativexpartial,out=negativex);
'nx', 'xy' and 'no' should be doing logical (bit-wise) negation, not arithmetic (2's complement) negation.

See this worksheet to understand how the ALU does arithmetic using logical negation.


Please edit you post to remove the HDL after solving your problem.

--Mark
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Please help with the ALU code bug.

rajat
Thanks sir for the guide it is very usefuland for replying.
Loading...