1
votes

In MIPS assembly, there are instruction SLT, SLTI, SLTU, SLTIU implemented as real hardware instructions. Also, there are instruction for conditional jump when comparing register with zero (greater, greater or equal, less and less or equal), BE and BNE with registers (except with use $zero register) don't matter in this case.

Maybe my question will be stupid, but I can't get with only combinations of this instructions pseudo-instruction that will be looking: BG Rz, Const, Label, meaning in C: if(Rz > direct_value) PC = Label;.

If we will try to reach it, SLTI (= Set If Less Than Immediate) can give us, with use BE with $zero, only two possible branching and that is register is less than immediate or register is greater or equal immediate, but not greater than immediate without using additional instructions.

Am I missing something? If not, how is this effectively solved?

Sorry for my English.

1
Why not reverse the operands? If immediate cannot be the first, load it to a reg. - Weather Vane
@WeatherVane Thank you for your answer. As I mentioned "I can't get with only combinations of this instructions pseudo-instruction that will be looking: BG Rz, Const, Label". So, there is no way to reach it with mentioned instructions? - Nik Novák
I don't understand the question. How can you use an instruction that doesn't exist? Does this help? - Weather Vane
@WeatherVane In short only with using two following instructions (not pseudo-instructions) perform pseudo-instruction BG Rz, Const, Label. Exactly like BGE, BGT, BLE, BLT are demonstrated on this page. However, on this page are only used both operands as registers. I need branch if register is greater than immediate. - Nik Novák
Subtract the immediate value, then branch test: two instructions. Or: branch <= and then unconditional jump. - Weather Vane

1 Answers

2
votes

Finally, I found exactly what I was looking for. Here is a screenshot that demonstrates everything.

BGTI pseudo-instruction translate