Search code examples
assemblyalu

Logisim ALU Red Lines - Not Understanding Causes and How to Fix


I'm working on a project where I need to create my own CPU for a specific instruction subset of MIPS. I will admit I thought I understood the single-cycle datapath until this project. So excuse my confusion.

My issue is with my ALU. The ALU Opcode is a 4-bit number, and the SubOp is a single-bit value. When I try to test my ALU, all of my lines to the output are red. I'm not sure why exactly. If I delete the NOR Gate's output, all other lines go black. And then when I change my Opcode (lower left of the image) from the AND gate (0x00) to another value, the output lines go red again.

While this ALU isn't completed yet, I'd like to ask for some input as to why this is happening? The inputs are 8-bits long. I've gone and broken this down to just a simple AND gate taking the 8-bit inputs and I still receive the red lines. No matter the selection of the Opcode, the ALUresult (bottom middle) produces errors.

What am I missing? enter image description here

I know there is a much easier way to lay this out. But I am trying to break down the ALU 'Opcode' into something that is easier for me to understand until testing has be completed. This is something I plan to work on once I understand this redline issue.


Solution

  • I'm not sure but I think that using the demultiplexers won't work:

    Typically the output of the "non-selected" channels of a demultiplexer has a constant value (for example 0 or 2^N-1) and not high-Z.

    And even if it is high-Z: If the input of some gate (such as an AND-gate) is high-Z the output is not necessarily high-Z. This depends on the tool used.

    Let's assume you want to do an addition and add the numbers 4 and 3. Let's assume a non-selected channel of a demultiplexer outputs 0.

    In this case the following will happen:

    One of the two demultiplexers passing the outputs to the adder and the subtractor will return 4 and 0, the other one will return 3 and 0.

    The adder will calculate: 4+3=7 while the subtractor will calculate 0-0=0.

    Both (!!!) values will now be fed to the "ALUresult" wire!!!

    What you typically do is you do ALL calculations (you pass the registers to ALL operations). So you always have ALL results (OR, AND, sum, difference, product, quotient, ...).

    Then you use a multiplexer (not a demultiplexer) to select the result you are interested in.