ALU zr ng problem

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

ALU zr ng problem

Hamza
I am stuck in zr and ng, I can't access the bits in out because it's output, and even if I make something like outin it says something like "cant access internal pins" please Help







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) or (out = x & y)?
        no; // negate the out output?
    OUT
        out[16], // 16-bit output
        zr,      // if (out == 0) equals 1, else 0
        ng;      // if (out < 0)  equals 1, else 0

    PARTS:
    //if nx then x=0
    Mux16(a=x , b=false , sel=zx , out=function1 );
   
    // if nx then x=!x
    Not16(in=function1 , out=notx );
    Mux16(a=function1 , b=notx , sel=nx , out=function2 );


    // if zx then y=0
    Mux16(a=y , b=false , sel=zy , out=function3 );

    // if ny then y=!y
    Not16(in=function3 , out=noty );
    Mux16(a=function3 , b=noty , sel=ny , out=function4 );

    // if f=1 then x+y else x & y

    Add16(a = function2, b =function4 , out = xplusy);
    And16(a= function2 , b= function4, out=xandy );

    Mux16(a=xandy , b=xplusy , sel=f , out=function5 );

    // if no=1 then out!=out
    Not16(in=function5 , out=notout );

    Mux16(a=function5 , b=notout , sel=no , out=out );
Reply | Threaded
Open this post in threaded view
|

Re: ALU zr ng problem

WBahn
Administrator
The trick that you need is explained in the documentation in a couple of places, depending on edition. But it is very easy to overlook.

While you can't use sub-bus addressing in a bus, you can sub-address part I/O pins, and you can use output pins multiple times (which is just a way of tying signals together).

So say you have Not16 part and you want to send all sixteen bits of it's output to another Not16 in order to get a buffered version of the data, but you also want to swap the upper and lower bytes at the input of another Not16 in order to get a version of the data with the bytes swapped. You could do that like the following:

Fred(in=data, out=inverted, out[0..7]=lobyte, out[8..15]=hibyte);
Not16(in=inverted, out=buffered);
Not16(in[0..7]=hibyte, in[8..15]=lobyte, out=swapped);