optimization - MIPS assembly - SLT vs SUB -


c language:

if(a < b) {    b += a; } 

assume $t1 = 1, $t2 = b.

mips assembly:

       slt $t0, $t1, $t2        beq $t0, $0, label        add $t2, $t2, $t1 label: ... 

but, can reached different way:

       sub $t0, $t1, $t2        bgez $t0, label        add $t2, $t2, $t1 label: ... 

my question:

it can proved every slt instruction can replaced form of add/sub instructions. so, what's key usage of instruction slt? can carry out detection shown here or else missed?

sorry english.


Comments