← 回題庫

卷別

計算機結構與作業系統(B)

選擇

國立臺灣大學 2022 · 考試 · 第 6 題

(5 pts) Below is the RISC-V assembly program generated for the body of function f: int f(int a, int b, int c). The program follows RISC-V's convention and uses registers x10-x18 to pass parameters and return values in function calls.

addi x2, x2, -16
sd   x1, 0(x2)
slli x5, x12, 5
sd   x5, 8(x2)
jal  x1, m
ld   x11, 8(x2)
lui  x12, 0x11232
addi x12, 0x334
ld   x1, 0(x2)
addi x2, x2, 16
jal  x0, g

Which of the following is the respective C code? Note that the addi instruction in RISC-V is sign-extended for immediate values.

  • (A)
    return g(m(a, b*5), 0x11232334)
  • (B)
    return g(m(a, b), c*32, 0x33411232)
  • (C)
    return g(m(a, b), 0x11232334, c*32)
  • (D)
    return g(m(a, c), b*32, 0x11232334)
  • (E)
    return g(m(a, b), c*32, 0x11232334)

標準解析

AI 生成