作者hardware (硬體)
看板Grad-ProbAsk
標題[理工] MIPS
時間Thu Jul 26 23:49:52 2012
Q: f=g-A[B[4]]
Assume the variable f,g,h,i and j are assigned to registers $s0,$s1,$s2,$s3
,$s4 respectively.the base adress of the arrays A and B are in registers
$s6,$s7
A:
MIPS
lw $t0,16($s7)
sll $t0,$t0,2 <-----
add $t0,$s6,$t0 <----- 這三行的意義不太懂,有請板上高手指教,thank you
lw $s0,0($t0) <-----
sub $s0 ,$s1,$s0
--
※ 發信站: 批踢踢實業坊(ptt.cc)
◆ From: 61.227.54.233
→ ddczx:第一行的$s0應該要改成$t0吧 07/26 23:55
感謝提醒:P
→ ddczx:第1行是t0=B[4], 第2行是t0=B[4]*4 07/27 00:01
→ ddczx:第3行是將A陣列的位址加上B[4]*4,即A[B[4]]的位址 07/27 00:01
為什麼B[4]*4,即A[B[4]]的位址呀?
→ ddczx:第4行是將A[B[4]]內容放到f 07/27 00:01
※ 編輯: hardware 來自: 61.227.54.233 (07/27 00:05)
→ ddczx:假設A的位址即A[0]是0X00,則A[1]的位址是0X04,因為1個整數是 07/27 00:11
→ ddczx:4個byte 07/27 00:12
→ hardware:感謝 07/27 00:18