Note #1

Basic operations

source code in C:

array[300] = a + array[300];

compiled to MIPS, suppose array in $t1 and a in $s2:

lw $t0, 1200($t1)
add $t0, $s2, $t0
sw $t0, 1200($t1)

then to machine code (Base 10):

op rs rt rd shamt funct address
35 9 8 / / / 1200
0 18 8 8 0 32 /
43 9 8 / / / 1200

notes that 3510 = 1000112, 4310 = 1010112.

Conditional Branches

source code in C:

if (i == j)
  f = g + h;
else
  f = g - h;

compiled to MIPS, suppose f to j in $s0 to $s4:

bne $s3, $s4, Else
add $s0, $s1, $s2
j Exit
Else: sub $s0, $s1, $s2
Exit:

Loops

source code in C:

while (array[i] == k)
  i += 1;

compiled to MIPS, suppose i in $s3, k in $s5 and array in $s6:

Loop: sll $t1, $s3 , 2   # Temp reg $t1 = i * 4
add $t1, $t1, $s6   # Thus we want $t1($s6)
lw $t0, 0($t1)
bne $t0, $s5, Exit
addi $s3, $s3, 1
j Loop
Exit:

Reference

P&H Computer Architecture and Design

最后編輯于
?著作權歸作者所有,轉載或內(nèi)容合作請聯(lián)系作者
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點,簡書系信息發(fā)布平臺,僅提供信息存儲服務。

推薦閱讀更多精彩內(nèi)容