21. Shared Functional Unit

Loading simulator…

Connect A_Reg and B_Reg to the four required operation paths.

For addition, use a 2-bit adder and preserve its carry-out:

ADD_Result = A_Reg + B_Reg
ADD_Carry = carry-out

For subtraction, implement:

SUB_Result = A_Reg - B_Reg

The subtraction carry output is interpreted as a no-borrow flag:

SUB_Carry = 1 → no borrow
SUB_Carry = 0 → borrow

Generate the other two operation results directly:

AND_Result = A_Reg & B_Reg
OR_Result  = A_Reg | B_Reg

Route the four 2-bit results to a 4:1 result-selection MUX controlled by ALU_Op:

00 → ADD_Result
01 → SUB_Result
10 → AND_Result
11 → OR_Result

Connect the selected 2-bit value to RESULT_REG.

Use the same ALU_Op selection to generate the CARRY output:

ADD → ADD_Carry
SUB → SUB_Carry
AND → 0
OR  → 0

Generate the remaining flags from the stored result:

ZERO = 1 when RESULT = 00
NEG  = RESULT[1]

Thus, RESULT, ZERO, and NEG represent the selected 2-bit operation result, while CARRY provides operation-specific arithmetic status.