HDL - PC.hdl but starting off with x2 8 bit registers

750 views Asked by At

So, I basically need to create a PC.hdl, but starting off with x2 8 bit registers. Here's the starting point:

// This file is BASED ON part of www.nand2tetris.org
// and the book "The Elements of Computing Systems"
// by Nisan and Schocken, MIT Press.
// File name: project03starter/a/PC.hdl

/**
 * A 16-bit counter with load and reset control bits.
 * if      (reset[t] == 1) out[t+1] = 0
 * else if (load[t] == 1)  out[t+1] = in[t]
 * else if (inc[t] == 1)   out[t+1] = out[t] + 1  (integer addition)
 * else                    out[t+1] = out[t]
 */

CHIP PC {
    IN in[16],load,inc,reset;
    OUT out[16];

    PARTS:
    // Something to start you off: you need *two* 8-bit registers
    Register(in=nextLow,  out=out[0..7],  out=currentLow,  load=true);
    Register(in=nextHigh, out=out[8..15], out=currentHigh, load=true);

    // Handling 'inc' to increment the 16-bit value also gets tricky
    // ... this might be useful
    And(a=inc, b=lowIsMax, out=incAndLowIsMax);
    // ...

    // The rest of your code goes here...
} 

I know how to do this normally with just handling the 16 bit but I'm not sure how to go about this with 8 bit registers.

Could anyone please help me with the correct solution?

Thanks.

1

There are 1 answers

3
MadOverlord On

Assuming you have an 8-bit adder, you can implement a 16-bit incrementer using 2 adders, one of which computes currentLow+1, and the other which computes currentHigh+(carry output of the low bits adder)