看板 Grad-ProbAsk 關於我們 聯絡資訊
※ 引述《pp393952 (囧?)》之銘言: : 99 成大工科(乙) 系統程式 : 第五題.. : 題目: : Assume that the variables f,g,h,i,and j are assigned to registers : $s0, $s1, $s2, $s3,and $s4, respectively. : Also, assume that the base address of integer arrays A & B are in $s6 and $s7. : For the MIPS assembly instructions bellow, what is the corresponding : C statment (in the simplest form)? : (a) add $s0, $s0, $s1 : add $s0, $s3, $s2 : add $s0, $s0, $s3 : (b) addi $s6, $s6, -20 : add $s6, $s6, $s1 : lw $s0, 8($s6) : (c) Assume that the regesters $s0, $s1, $s2, $s3 contain the values 10, 20, : 30, and 40, respectively. : Also, assume that register $s6 contains the value 256, and tht memory : contains the following values: : Address│Value : ────┼─── : 256 │ 100 : ────┼─── : 260 │ 200 : ────┼─── : 264 │ 300 : Find the value of $s0 at the end of the assembly code in (a) and (b), : respectively. : 第(a)題我自己寫的答案是 : f = f + g; : f = i + j; ^^ i+h吧? : f = f + i; : (b)跟(c)我就不知道怎麼翻譯... (b) 我會寫f = A[g/4 - 3],但真正的解答也許要用Pointer表達才會對 簡單來說前兩行是 $s6 = $s6 - 20 + $s1,其中$s6是A陣列的Base Address 然後lw $s0, 8($s6) 相當於$s0 = Memory[$s6+8] 所以最後翻譯出來會是$s0 = Memory[A的Base Address-20+$s1+8] = Memory[A的Base Address+$s1-12] 也因為MIPS中Word Address是4的倍數,所以「也許」相當於A[g/4-3] 有沒有人有更好的寫法? (c) 兩個答案:(a) 應該是110 (b) 根據上面,Memory[256+$s1-12] ($s1 = 20) = Memory[264] 所以是300 : 麻煩組合語言高手幫我解答一下~"~ 感謝 -- ※ 發信站: 批踢踢實業坊(ptt.cc) ◆ From: 220.131.200.224