← 回題庫

卷別

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

選擇

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

(5 pts) Consider the RISC-V code below were executed concurrently on two cores.

[x2] = 1
[x3] = 1

ld   x1, 0(x2)
addi x1, x1, 1
sd   x1, 0(x2)
ld   x4, 0(x3)
add  x4, x1, x4
sd   x4, 0(x3)

Memory is shared by the two cores. Before executing the code, assuming registers x2 and x3 of each of the cores contain different values (x2core0≠x3core0x2_{core0} \ne x3_{core0} and x2core1≠x3core1x2_{core1} \ne x3_{core1}). The same register x2 and x3 of the two cores respectively contain the same value (x2core0=x2core1x2_{core0} = x2_{core1} and x3core0=x3core1x3_{core0} = x3_{core1}). The memory location x2 and x3 each contains the integer value 1 before executing the code. Assuming no instruction reordering is possible. What are all the possible values of x2 and x3 after code execution has completed?

  • (A)
    x2 = 2, x3 = 3 or 4 or 5
  • (B)
    x2 = 2 or 3, x3 = 3 or 4 or 5 or 6
  • (C)
    x2 = 2 or 3, x3 = 3 or 4 or 5 or 6 or 7
  • (D)
    x2 = 1 or 2 or 3, x3 = 2 or 3 or 4 or 5
  • (E)
    x2 = 3, x3 = 4 or 5 or 6 or 7

標準解析

AI 生成