[MIPS] Conditional branch Instruction (slt)
BEQ와 BNE로 같다(==)와 다르다(!=)라는 수식을 사용할 수 있지만
작다(<), 크다(>) 등은 어떻게 표현할 수 있을까요 ?
그렇게 MIPS에서 특별하게 만들어진 새로운 instruction이 있습니다.
바로 slt instruction 입니다.
(Set less than)
Ex 1) slt $t0, $s1, $s2 # if $s1<$s2 then $t0 = 1
else $t0 = 0
($s1와 $s2 비교해서 같으면 $t0를 1로 set하고 다르면 $t0를 0으로 clear한다.)
Ex 2) slt rd, rs, rt # rt = (rs<rt) ? 1 : 0
slt - set less than instruction
rd - destination
rs, rt - source
rs와 rt를 비교해서 같으면 1로 set, 다르면 0으로 clear한다.
Set Less Than - R type 일 때
SLT $s1, $s2, $s3 : if ($s2<$s3) $s1 ← 1 else $s1 ← 0
op = 0 | rs = 18 | rt = 19 | rd = 17 | shamt = 0 | func = 42 |
(R-type에서 op code는 항상 0)
Set Less Than immediate - I type 일 때
SLTI $s1, $s2, 100 : if ($s2<100) $s1 ← 1 else $s1 ← 0
op = 10 | rs = 17 | rt = 18 | constant = 100 |
(I-type에서 SLTI instruction은 op code 10)
이 외의도 만들어진 instruction의 set이 있습니다.
① bgt - banch if greater than
② bge - branch if greater thean or equal
③ blt - branch if less than
④ ble - branch if less than or equal
etc.
◡̈