1
\$\begingroup\$

I'm building an 8-bit computer using the Ben Eater's videos and I would like to improve the ALU, e.g. add nand bitwise operation because every logic gates can be built from this.

But I ask myself if it would be possible to have shift (left/right) operation using this nand gate?

\$\endgroup\$
5
  • \$\begingroup\$ A Shift (left/right) register can be made with flip-flops. Those flip-flop can also be made with NAND gate. So yes, it's possible \$\endgroup\$
    – M.Ferru
    Commented May 24, 2017 at 9:50
  • \$\begingroup\$ I notice Ben doesn't limit himself to just using nand gates to create all other functions so why not just use a suitable shift register IC and save yourself the hassle. \$\endgroup\$ Commented May 24, 2017 at 10:26
  • 1
    \$\begingroup\$ @M.Ferru, an ALU wouldn't use flip-flops, wastes a clock cycle, it'd be combinatorial. \$\endgroup\$
    – TonyM
    Commented May 24, 2017 at 10:35
  • \$\begingroup\$ @TonyM The shift operation takes just 1 clock cycle with flip-flops. Am I right? \$\endgroup\$
    – M.Ferru
    Commented May 24, 2017 at 10:37
  • \$\begingroup\$ But @M.Ferru, as KillKem says, a fixed shift is just wiring into the ALU's feedback mux. Been that way in CPUs since the 70s. Why waste a second clock cycle beyond the one you need to register the result? \$\endgroup\$
    – TonyM
    Commented May 24, 2017 at 10:55

1 Answer 1

2
\$\begingroup\$

A shift operation like what a >> or << compiles to is done with a (barrel) shifter.

You can build one by using a decoder and a cross bar of links with AND gates connecting the verticals and the horizontals. Then the output of the decoder will travel diagonally.

Another option is to use muliplexers and have several layers:

schematic

simulate this circuit – Schematic created using CircuitLab

This is a 4 bit logical right-shift circuit. ShiftAmount0 is the least significant bit and shiftAmount1 is the next least significant bit.

You can grow this circuit by making the 1 input of the mux double the jump it makes. You can also connect the 1 inputs of the higher significant bits to the lower significant bits (for barrel shift) or the highest bit (for arithmetic shift). This you can do with a few AND gates to select the correct behavior.

\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.