assemblymipscpucpu-architecturealu

Add instruction greater than immediate to MIPS


This is a homework question and i am stuck because i dont know how to evaluate if a value is greater than another.

Here is the instruction i need to add:

The sgti instruction - set on greater than immediate - is an instruction which allows setting a register to 1 when one value is greater than the other:

sgti rd, rs, imm #if R[rs] > ext32 (imm) then R[rd] = 1 otherwise R[rd] = 0

Here is my circuit:

Here is my circuit: I know for example how to evaluate if a value == another value by doing a substraction in the UAL and looking if the zero is set, but i dont know how to check if greater than. Thanks


Solution

  • For signed addition, overflow happens

    For signed subtraction, overflow happens

    A quick read of these should make mathematical sense (the sum of two positive numbers cannot be negative).

    You can check for these conditions to determine overflow.

    When overflow happens, then you simply compare the signs of the inputs to determine the result.


    So, here's an approach:

    The sign bit is the high bit, the MSB, aka bit 31.