← All problems

MIPS ALU

Medium · Combinational · SystemVerilog · VHDL

Design a 32-bit MIPS ALU.

aluc selects the operation, and r is its result:

alucOperationr
6'b100000ADDlow 32 bits of a + b
6'b100001ADDUlow 32 bits of a + b
6'b100010SUBlow 32 bits of a - b
6'b100011SUBUlow 32 bits of a - b
6'b100100ANDbitwise AND of a and b
6'b100101ORbitwise OR of a and b
6'b100110XORbitwise XOR of a and b
6'b100111NORbitwise NOR of a and b
6'b101010SLT1 if a is less than b read as two's-complement, else 0
6'b101011SLTU1 if a is less than b read as unsigned, else 0
6'b000000SLLb shifted left by a
6'b000010SRLb shifted right by a, filling with 0s
6'b000011SRAb shifted right by a, filling with copies of its sign bit
6'b000100SLLVb shifted left by a[4:0]
6'b000110SRLVb shifted right by a[4:0], filling with 0s
6'b000111SRAVb shifted right by a[4:0], filling with copies of its sign bit
6'b001111LUIa[15:0] in the upper half, 0s in the lower half

Any other aluc gives r = 0.

zero is high when r is 0, and negative is r[31], for every operation. carry is the carry out of a + b for ADD and ADDU and the borrow of a - b (high when a is less than b read as unsigned) for SUB and SUBU. overflow is high when, for ADD or SUB with a and b read as two's-complement, the true result does not fit in 32 bits. flag is high when SLT or SLTU finds a less than b. Each of carry, overflow and flag is 0 for every operation not named with it.

The module is combinational.

Open this challenge in the editor →