匯編
from my wp blog
MIPS
獲取一個32位整數(shù)
lui $s0, 61
ori $s0, 1234
不使用addi:addi會將16位數(shù)最左位補全為32位
無條件跳轉(zhuǎn)
j 10000
先左移兩位湿蛔,再將PC前4位放到前面店溢,構(gòu)成絕對目標(biāo)地址
條件跳轉(zhuǎn)
bne $s0, $s1, Exit
Exit左移兩位,跳轉(zhuǎn)相對于PC的地址(pc+Exit<<2)矩桂,用于循環(huán)loop和if中
條件跳轉(zhuǎn)不能遠(yuǎn)跳沸移,用無條件代替
beq $s0, $s1, L1
...
bne $s0, $s1, L2
j L1
L2;
范圍檢查
if($a1>=$t2 && $a1<0) goto indexOutOfBounds
sltu $t0, $a1, $t2 #Temp
reg$t0=0 if k>=length or k<0
beq$ t0, $zero, IndexOutofBounds