免費詳解 / 交大 / 硬體 / 104

104 交大資工所考古題解答|硬體逐題詳解

104 交大資工所硬體考古題的逐題詳解,共 38 題,免費公開。

逐題詳解

14 分

Assume there are 1,000 processes of ProgramX (Figure 1) running on a system equipped with an Intel Core i5 processor. If we randomly pick one of the processes, which of the following CPU states (a~e as shown in Figure 1) is the most likely one that the process will be at?

int main()
{
  while(1);
  return 0;
}

(Figure 1:process state diagram,(a) new、(b) terminated、(c) ready、(d) running、(e) waiting)

ProgramX 是純 CPU-bound 的無窮迴圈,沒有 I/O,不會進 waiting

1000 個這樣的 process 搶少數幾個 core,任何時刻只有極少數在 running,其餘全排在 ready queue

(c) ready

24 分

Which of the following inter-process communication mechanisms requires explicit synchronization in general? (a) Shared memory (b) Message queue (c) Signal (d) TCP/IP (e) Pipe

message queue、pipe、TCP/IP 的收送本身由 kernel 保證同步;signal 不是傳資料的通道

shared memory 是直接給一塊共用記憶體,互斥要自己用 semaphore/mutex 做

(a)

34 分

Which of the following statements about memory management is correct?

(a) To allocate contiguous memory from free holes, the best-fit algorithm is the optimum solution in memory utilization.

(b) Pure segmentation suffers from internal fragmentation.

(c) A system can detect thrashing by using a figure, in which CPU utilization is plotted against the execution time.

(d) For first-in-first-out page replacement, the page-fault rate will definitely not increase as the number of frames increases.

(e) None of the above is correct.

(a) best-fit 只是啟發式,不保證最佳利用率 → F

(b) pure segmentation 的 segment 大小不固定,產生的是 external fragmentation → F

(c) 判斷 thrashing 要畫 CPU utilization 對 degree of multiprogramming,不是對執行時間 → F

(d) FIFO 有 Belady's anomaly,frame 變多 fault rate 可能上升 → F

四項都不對

(e)

44 分

Suppose that we use a three-level paging system, and it takes 20 ns to search the TLB (translation look-aside buffer) and the TLB hit ratio is 90 percent. The effective memory-access time by the probability is 202 ns. If we speed up the memory and the new memory access time is 50% of the original one (other conditions are the same), the new effective memory-access time is \(T\) ns. Please choose the correct value of "round(\(T\)) mod 5". (Hint: round(\(T\)) returns the nearest integer of \(T\). You do not have to consider page faults.) (a) 0 (b) 1 (c) 2 (d) 3 (e) 4

一次記憶體存取 \(m\) ns

TLB hit:\(20+m\);TLB miss:查 TLB 20,走三層 page table 3 次,再讀資料 1 次,\(20+3m+m=20+4m\)

\(\text{EAT}=0.9(20+m)+0.1(20+4m)=20+1.3m=202\) → \(m=140\)

記憶體變成原來的 50%:\(m'=70\),\(T=20+1.3\times70=111\)

\(111\bmod5=1\)

若把 TLB hit 也當成還要走完三層 page table,係數是 3.1,\(m\) 一樣砍半,T 仍是 111

(b)

54 分

A large file \(M\) of size 3 Giga bytes needs to be transferred from Alice to Bob over the Internet. Alice's RSA public key, secret key, one-time DES key are \(K_{pa}\), \(K_{sa}\), and \(K_{da}\), respectively. Bob's RSA public key, secret key, are \(K_{pb}\) and \(K_{sb}\), respectively. To achieve both confidentiality and authentication, what will be the best way for Alice to send the file \(M\)? \(\{M\}_K\) represents the encryption of \(M\) using \(K\). Checksum function is already embedded in the operations.

(a) \(\{\{M\}_{K_{sa}}\}_{K_{pb}}\) (b) \(\{\{M\}_{K_{pb}}\}_{K_{sa}}\) (c) \(\{\{M\}_{K_{pb}},\{K_{da}\}_{K_{pb}}\}_{K_{sa}}\) (d) \(\{\{M\}_{K_{da}},\{K_{da}\}_{K_{sa}}\}_{K_{pb}}\) (e) \(\{M\}_{K_{da}},\ \{\{K_{da}\}_{K_{sa}}\}_{K_{pb}}\)

3 GB 的 \(M\) 不能直接用 RSA 加密(太慢) → \(M\) 用 one-time DES key \(K_{da}\) 加密:\(\{M\}_{K_{da}}\)

\(K_{da}\) 先用 Alice 的 secret key \(K_{sa}\) 簽章 → authentication;再用 Bob 的 public key \(K_{pb}\) 加密 → 只有 Bob 解得開(confidentiality):\(\{\{K_{da}\}_{K_{sa}}\}_{K_{pb}}\)

(a)(b)(c)(d) 都要把整個 \(M\) 丟進 RSA,成本上做不到

(e)

64 分

Unix-like operating systems use access permissions to control file access. Given an access permission 0751, which of the following statement is correct:

(a) Both the owner and group members can read and execute the file (b) The group members can read and write the file (c) The group members can write and execute the file (d) Others can read the file (e) Others can write the file

0751:owner 7 = rwx,group 5 = r-x,others 1 = --x

(a) owner 與 group 都同時有 r、x → T

(b)(c) group 沒有 w → F;(d) others 沒有 r → F;(e) others 沒有 w → F

(a)

74 分

Which of the following statement is correct?

(a) Instructions addi, beq, and j (jump) all need to perform sign extension.

(b) The most significant bit of 2's complement representation is the sign bit — a sign bit of 1 indicates a positive number.

(c) The range of numbers represented by \(n\)-bit 2's complement is \(-(2^{n-1}-1)\sim0\sim(2^{n-1}-1)\).

(d) Consider an addition of two 32-bit signed integers with a 32-bit ripple-carry adder, which consists of 32 1-bit full adders connected in series: if the carry-in and the carry-out of the most-significant-bit (MSB) full adder have different logic values, then there is an overflow due to the addition.

(e) The operation of adding one very large positive integer and one very small negative integer may produce an overflow.

(a) addi、beq 要做 sign extension;j 的 26-bit target 左移 2 後接上 PC 高位,不做 sign extension → F

(b) sign bit 為 1 是負數 → F

(c) 2's complement 的範圍是 \(-2^{n-1}\sim2^{n-1}-1\),那個是 1's complement/sign-magnitude 的範圍 → F

(d) MSB 的 carry-in 與 carry-out 不同就是 overflow → T

(e) 一正一負相加,結果落在兩數之間,不可能 overflow → F

(d)

84 分

Which of the following statement is correct?

(a) Pipelining improves the performance of a processor by decreasing the latency of a job (e.g., an instruction) to be done.

(b) The more balanced pipeline stages a specific datapath has, the higher performance this pipelined datapath can achieve.

(c) Every single instruction, when being executed in a \(n\)-stage pipelined datapath, consistently needs \(n\) clock cycles before its execution is completely done.

(d) It is likely to have fewer hazards and less severe impact of hazards with deeper design of pipelining (i.e., more pipeline stage).

(e) The number of pipeline stages monotonically grows with technology advance such as shrinking transistor size.

(a) pipeline 提高的是 throughput,單一指令的 latency 反而略增 → F

(b) clock cycle 由最慢的 stage 決定,stage 越平均、cycle 越短、效能越高 → T

(c) 碰到 hazard 要 stall,就不只 \(n\) 個 cycle → F

(d) pipeline 越深,hazard 越多、branch penalty 越大 → F

(e) stage 數並非隨製程單調成長(power 限制下還縮回來過) → F

(b)

94 分

Which of the following statement is correct?

(a) For write-back cache, both cache and memory will be updated on data-write hit.

(b) For write-through cache, multiple writes within a block may require only one write to the memory.

(c) Write-through is widely used in virtual memory in order to keep memory and disk consistent.

(d) First-level caches are more concerned about hit time, and second-level caches are more concerned about miss rate.

(e) Increase associativity may increase miss rate due to conflict misses.

(a) write-back 在 write hit 只更新 cache → F

(b) 「同一 block 多次寫只回寫一次」是 write-back 的特性 → F

(c) virtual memory 對 disk 用 write-back,write-through 成本太高 → F

(d) L1 重視 hit time,L2 重視 miss rate → T

(e) 提高 associativity 是用來減少 conflict miss → F

(d)

104 分

In a memory system, there is one TLB, one physically addressed cache, and one physical main memory. Assuming all memory addresses are translated to physical addresses before the cache is accessed. Which of the following events is impossible in memory system? (Note: PT stands for page table)

(a) TLB: hit, PT: hit, Cache: miss (b) TLB: miss, PT: hit, Cache: hit (c) TLB: miss, PT: hit, Cache: miss (d) TLB: miss, PT: miss, Cache: miss (e) TLB: hit, PT: miss, Cache: hit

TLB hit 表示這個 page 的 translation 有效,page 一定在 physical memory 裡,不可能 page table miss(page fault)

其他四種組合都可能發生

(e)

114 分

Assume the processor of a Windows 8 laptop is executing some user-mode code. Which of the following events will cause a user-mode to kernel-mode transition (i.e. involving execution of kernel-mode code)?

(a) Process context switch (b) Thread context switch (the threads are native Windows threads) (c) Interrupt handling (d) Open a file on the disk (e) Page fault handling

(a)(b) context switch 由 kernel 執行(Windows 的 thread 是 kernel thread) → T

(c) interrupt handler 在 kernel mode → T;(d) open file 是 system call → T;(e) page fault handler 在 kernel → T

(a), (b), (c), (d), (e)

124 分

Which of the following statements about file systems are correct?

(a) A remote directory can only be mounted over the root directory through the network file systems.

(b) Linked allocation does not suffer from external fragmentation.

(c) If the size of a block is 1024 bytes and a pointer require 32 bits, in a two-level index system, a file associated with a first-level index block can have a size of up to 256MB.

(d) Using on-line compaction can efficiently conquer the fragmentation problem of contiguous allocation.

(e) Compared with conventional linked allocation, caching the file-allocation tables (FAT) in memory can improve the efficiency of random access.

(a) remote directory 可以掛在任何 mount point → F

(b) linked allocation 的 block 散落各處,沒有 external fragmentation → T

(c) \(1024/4=256\) 個 pointer,two-level index 上限 \(256\times256\times1024\text{ B}=64\text{ MB}\),不是 256 MB → F

(d) compaction 要搬移大量資料,成本高 → F

(e) FAT 放進記憶體,不必為了追 pointer 一直讀磁碟,random access 明顯改善 → T

(b), (e)

134 分

Which of the following statements are true?

(a) Smartphones normally do not have hard disk drives (HDDs).

(b) Solid state drives (SSDs) are replacing HDDs where speed, power consumption and durability are more important considerations.

(c) Secondary storage is normally non-volatile.

(d) Cloud storage has become a popular way for data storage.

(e) Wearable devices are normally equipped with hard disk drives to increase its storage space.

(a)(b)(c)(d) 都是常識性的敘述 → T

(e) wearable device 的體積與耗電不允許裝 HDD,靠 flash → F

(a), (b), (c), (d)

144 分

Which of the following are true?

(a) Android applications on Google Play (formerly known as Google Android Market) are trustworthy. (b) Firewall can filter network traffic. (c) Intrusion detection system (IDS) can analyze malicious network traffic. (d) VPN (virtual private network) gateways can be used to establish confidential tunnels between two network gateways. (e) Many routers are equipped with firewall and VPN functions.

(a) Google Play 上的 app 並非都可信,惡意 app 混進去是常態 → F

(b)(c)(d)(e) 都是 firewall、IDS、VPN 的標準功能描述 → T

(b), (c), (d), (e)

154 分

Which of the following 32-bit hexadecimal data will have identical storage sequence in the (byte-addressable) memory no matter the machine is big-endian or little-endian?

(a) AABBAABBhex (b) ABBAABBAhex (c) ABBBBBABhex (d) ABCDCDABhex (e) ABCDDCBAhex

32 bit = 4 個 byte;big-endian 與 little-endian 存出來的 byte 序列恰好相反,要相同,byte 序列必須是回文(以 byte = 兩個 hex 字為單位)

選項byte 序列反轉回文?
(a)AA BB AA BBBB AA BB AAF
(b)AB BA AB BABA AB BA ABF
(c)AB BB BB ABAB BB BB ABT
(d)AB CD CD ABAB CD CD ABT
(e)AB CD DC BABA DC CD ABF

(c), (d)

164 分

Which of the following statements are correct?

(a) Given that every 1-bit ALU has a propagation delay of 1 unit, the cumulative propagation delay for an SLT (set-on-less-than) operation is 32 units in the worst case.

(b) The operation of 00110011 (multiplicand) * 11011011 (multiplier) based on the Booth's algorithm requires 2 additions and 3 subtractions.

(c) The Booth's algorithm is always better than traditional multiplication in terms of the total number of required additions and subtractions.

(d) \(0.3125\times2^{130}\) can be represented by the IEEE 754 single-precision floating-point standard format without any loss of accuracy.

(e) IEEE 754 double-precision floating-point representation is exactly 2X more precise than the single-precision counterpart.

(a) SLT 要先讓減法從 bit 0 ripple 到 bit 31(32 units),再把 bit 31 的 Set 送回 bit 0 的 Less 輸入,worst case 超過 32 units(33) → F

(b) multiplier 11011011 在最右補 \(b_{-1}=0\),由右往左看 \((b_i,b_{i-1})\):

\(i\)01234567
\((b_i,b_{i-1})\)(1,0)(1,1)(0,1)(1,0)(1,1)(0,1)(1,0)(1,1)
動作減無加減無加減無

3 次減、2 次加 → T

(c) multiplier 是 0101… 交替型時,Booth 反而比傳統多做很多次加減 → F

(d) \(0.3125=1.25\times2^{-2}\),整個值是 \(1.25\times2^{128}\),exponent 128 超過 single 的上限 127,overflow → F

(e) 尾數 52 bits 對 23 bits,不是剛好兩倍 → F

(b)

174 分

Which of the following statements are correct?

(a) Trying to allow some instructions to take fewer cycles does not help, since the throughput is determined by the clock cycle; the number of pipeline stages per instruction affects latency, not throughput.

(b) Instead of trying to make instructions take fewer cycles, we should explore making the pipeline longer (deeper), so that instructions take more cycles, but the cycles are shorter. This could improve performance.

(c) A data hazard between two adjacent R-type instructions can always be resolved with forwarding.

(d) Perfect branch prediction (i.e., 100% prediction accuracy) combined with data forwarding would allow a processor to always keep its pipeline full.

(e) If we use an instruction from the fall-through (untaken) path to fill in a delay slot, we must duplicate the instruction.

(a) pipeline 滿載時 throughput 由 clock cycle 決定,讓某些指令少走幾個 cycle 只改 latency → T

(b) 切更深、每個 cycle 更短(superpipelining),could improve performance → T

(c) 相鄰兩條 R-type 靠 EX/MEM→EX forwarding 一定接得上 → T

(d) load-use hazard 即使 branch prediction 100% 也一定要停一拍 → F

(e) 需要複製指令的是從 branch target 那條路徑取;fall-through 的指令本來就在原位,直接搬進 delay slot 即可 → F

(a), (b), (c)

184 分

Suppose you have a machine which executes a program spending 50% of execution time in floating-point multiply, 20% in floating-point divide, and 30% in integer instructions. Which of following statements are correct?

(a) If we make the floating-point divide run 3 times faster, the speedup relative to original machine is about 0.87.

(b) If we make the floating-point multiply run 8 times faster, the speedup relative to original machine is about 1.78.

(c) If we make both divide and multiply run faster as described in (a) and (b), the speedup relative to original machine is about 2.33.

(d) If we can make all the floating-point instructions run 15 times faster, the percent of floating-point instructions need to be about 90.36 in order to achieve a speedup 4.

(e) The rule stating that the performance enhancement possible with a given improvement is limited by the amount that the improved feature is used is called Moore's law.

(a) 新時間 \(0.5+0.2/3+0.3=0.867\),speedup \(=1/0.867\approx1.15\);0.87 是時間比,不是 speedup → F

(b) \(0.5/8+0.2+0.3=0.5625\),speedup \(=1.78\) → T

(c) \(0.5/8+0.2/3+0.3=0.4292\),speedup \(=2.33\) → T

(d) 設 FP 佔 \(f\):\(\dfrac{1}{(1-f)+f/15}=4\) → \(1-\tfrac{14}{15}f=\tfrac14\) → \(f=\tfrac{0.75\cdot15}{14}=0.8036\),是 80.36% → F

(e) 這條是 Amdahl's law → F

(b), (c)

194 分

Consider two different implementations, M1 and M2, of the same instruction set. There are three classes of instructions (A, B, and C) in the instruction set. M1 has a clock rate of 80MHz and M2 has a clock rate of 100MHz. The average number of cycles for each instruction class and their frequencies (for a typical program) are as the table below. Which of following statements are correct (Note, the MIPS in these statements stand for Millions of Instruction Per Second)?

Instruction classM1 cycles/classM2 cycles/classFrequency
A1260%
B2330%
C4410%

(a) The average CPI for M1 is 1.6 (b) The average CPI for M2 is 2.5 (c) M2 has higher MIPS rating than M1 (d) If we change CPI of instruction class A for M2 to 1, M2 has higher MIPS rating than M1 (e) If we increase the clock rate of M1 to 100MHz without affecting the CPI of A, B, and C. The speedup of M1 is 0.8.

(a) \(\text{CPI}_{M1}=1(0.6)+2(0.3)+4(0.1)=1.6\) → T

(b) \(\text{CPI}_{M2}=2(0.6)+3(0.3)+4(0.1)=2.5\) → T

(c) \(\text{MIPS}_{M1}=80/1.6=50\),\(\text{MIPS}_{M2}=100/2.5=40\),M2 較低 → F

(d) A 的 CPI 改成 1:\(\text{CPI}_{M2}=0.6+0.9+0.4=1.9\),\(\text{MIPS}=100/1.9\approx52.6\gt50\) → T

(e) clock 80→100 MHz、CPI 不變,speedup \(=100/80=1.25\) → F

(a), (b), (d)

204 分

Assume a 128KB direct-mapped cache with a 32-byte block. Consider a video streaming workload that accesses a 64KB working set sequentially with the following address stream: 0, 2, 4, 6, 8, 10, 12, 14, 16, … etc. Which of the following statements are correct?

(a) The miss rate is 1/32. (b) All the misses are compulsory misses based on the 3Cs model. (c) The miss rate is sensitive to the size of the cache. (d) The miss rate is sensitive to the size of the working set. (e) The miss rate is sensitive to the block size.

stride 2 bytes、block 32 bytes → 每個 block 被連續存取 16 次:第一次 miss,其餘 15 次 hit

(a) miss rate \(=1/16\) → F

(b) cache 128 KB 裝得下 64 KB 的 working set,所有 miss 都是第一次碰到 block 的 compulsory miss → T

(c)(d) 裝得下的前提下,改 cache 或 working set 大小,miss rate 仍是 1/16 → F

(e) miss rate \(=\dfrac{2}{\text{block size}}\),直接由 block size 決定 → T

(b), (e)

215 分(題組 A:21–23 全對)

A. Consider the execution of the following set of processes on a single-core processor:

ProcessCreation TimeRequired Execution Time
\(P_1\)030
\(P_2\)1010
\(P_3\)2020
\(P_4\)2010
\(P_5\)9010

21. Assume we use first-come-first-served (FCFS) scheduling. How long will it take for the four processes to complete? (a) 60 (b) 70 (c) 80 (d) 90 (e) 100

FCFS:\(P_1\):0–30;\(P_2\):30–40;\(P_3\):40–60;\(P_4\):60–70;\(P_5\) 在 90 才到:90–100

題目說「four processes」但表有五個,\(P_1\)–\(P_4\) 做完是 70、全部五個是 100,兩種讀法不同

官方:送分(第 21 題,不選特定答案)

22題組 A

22. Find a non-preemptive scheduling that minimizes the average waiting time. The minimal average waiting time is a two-digit number \(D_1D_0\). Please select from the following the value of \(D_1\). (a) 0 (b) 1 (c) 2 (d) 3 (e) 4(題組 A 的表同第 21 題)

非搶佔,但 CPU 可以先閒著等短工作進來(\(P_1\) 在 0 到,先不跑;等 \(P_2\))

順序Process開始結束waiting
1\(P_2\)10200
2\(P_4\)20300
3\(P_3\)305010
4\(P_1\)508050
5\(P_5\)901000

總 waiting \(=60\),平均 \(=60/5=12\) → \(D_1=1,\ D_0=2\)

若 0 時刻就讓 \(P_1\) 先上 CPU,之後再怎麼排最好也只有平均 14

(b)

23題組 A

23. Continue from previous question. Please select from the following the value of \(D_0\). (a) 1 (b) 2 (c) 3 (d) 4 (e) 5

平均 waiting time \(=12\)(見第 22 題) → \(D_0=2\)

(b)

245 分(題組 B:24–28 全對)

B. A system provides users paging-based virtual-memory space of \(2^{16}\) bytes, it has 3 physical frames and the page size is \(2^{10}\) bytes. When a process accesses a sequence of the hexadecimal virtual addresses: 0x0A08, 0x012C, 0x05DF, 0x0722, 0x08A6, 0x0B33, 0x0428, 0x0CF2, 0x0160, 0x0D5F. The physical memory address of the last access "0x0D5F" is "X" by the LRU algorithm. \(X/4=X_4\cdot5^4+X_3\cdot5^3+X_2\cdot5^2+X_1\cdot5^1+X_0\) (\(0\le X_0,X_1,X_2,X_3,X_4\lt5\)). Please choose the correct values of \(X_4,X_3,X_2,X_1\), and \(X_0\) in the following.

24. \(X_4=\)?(a) 4, (b) 3, (c) 2, (d) 1, (e) 0

page size \(2^{10}\) → page number = 位址右移 10 bits

#位址page結果frame 內容(frame 0/1/2)
10x0A082miss2/-/-
20x012C0miss2/0/-
30x05DF1miss2/0/1
40x07221hit
50x08A62hit
60x0B332hit
70x04281hit
80x0CF23miss,LRU 是 page 0(最後用在 #2)→ 換掉 frame 12/3/1
90x01600miss,LRU 是 page 2(最後用在 #6)→ 換掉 frame 00/3/1
100x0D5F3hit,在 frame 10/3/1

frame \(k\) 的起點是 \(k\cdot1024\);最後一次存取在 frame 1,offset \(=\text{0x0D5F}\bmod1024=\text{0x15F}=351\)

\(X=1\cdot1024+351=1375=2\cdot5^4+1\cdot5^3+0\cdot5^2+0\cdot5+0\)

題目寫 \(X/4=\ldots\),但 \(X=1375\) 本身才對得上官方答案 2, 1, 0, 0, 0(\(1375/4\) 不是整數);這裡按官方答案,以 \(X\) 展開 5 進位

\(X_4=2\):(c)

25題組 B

25. \(X_3=\)?(a) 4, (b) 3, (c) 2, (d) 1, (e) 0(同題組 B)

\(X=1375=2\cdot5^4+1\cdot5^3+0\cdot5^2+0\cdot5^1+0\cdot5^0\)(見第 24 題)

\(X_3=1\):(d)

26題組 B

26. \(X_2=\)?(a) 4, (b) 3, (c) 2, (d) 1, (e) 0(同題組 B)

\(X=1375=2\cdot5^4+1\cdot5^3+0\cdot5^2+0\cdot5^1+0\cdot5^0\)(見第 24 題)

\(X_2=0\):(e)

27題組 B

27. \(X_1=\)?(a) 4, (b) 3, (c) 2, (d) 1, (e) 0(同題組 B)

\(X=1375=2\cdot5^4+1\cdot5^3+0\cdot5^2+0\cdot5^1+0\cdot5^0\)(見第 24 題)

\(X_1=0\):(e)

28題組 B

28. \(X_0=\)?(a) 4, (b) 3, (c) 2, (d) 1, (e) 0(同題組 B)

\(X=1375=2\cdot5^4+1\cdot5^3+0\cdot5^2+0\cdot5^1+0\cdot5^0\)(見第 24 題)

\(X_0=0\):(e)

295 分(題組 C:29–33 全對)

C. Consider the following MIPS code in a 5-stage pipelined CPU (see Figure 1).

# memory address: instruction in the memory
36: sub $1, $4, $8
40: beq $1, $3, 7
44: and $12, $2, $5
48: or  $13, $2, $6
...
72: lw  $4, 50($7)
76: add $14, $4, $2
80: slt $15, $6, $7

Figure 2 shows the pipeline state (in clock cycle 3) when the branch instruction (beq $1, $3, 7) is in the ID stage(圖:IF 是 and $12,$2,$5、ID 是 beq $1,$3,7、EX 是 sub $1,$4,$8,MEM/WB 是更早的指令). Assume that (i) this branch will be taken, (ii) branch outcome are to be determined in the ID stage, and (iii) although not shown in the figure, forwarding to the ID stage (from EX/MEM pipeline registers) is available.

29. In the next clock cycle (clock cycle 4), what is the output value of the ALU (for program counter addition) in the IF stage? (a) 40 (b) 44 (c) 48 (d) 72 (e) 76

cycle 3:IF 是 44 的 and,ID 是 40 的 beq,EX 是 36 的 sub

sub 寫 \(\$1\),beq 在 ID 就要讀 \(\$1\);sub 的結果要到 cycle 3 結束才寫進 EX/MEM,ID 要的值 cycle 3 還沒有 → hazard detection:停一拍

停一拍:PC 與 IF/ID 都不更新,EX 灌進 bubble(cycle 4 才能從 EX/MEM 把 sub 的結果 forward 給 ID)

cycle 4:PC 仍是 44,IF stage 的加法器輸出 \(=44+4=48\)

(c)

30題組 C

30. In the next clock cycle (clock cycle 4), what is the output value of the ALU (for program counter addition) in the ID stage? (a) 40 (b) 44 (c) 48 (d) 72 (e) 76(同題組 C)

ID stage 的加法器算 branch target:\((\text{PC}+4)+\text{offset}\times4\),beq 的 \(\text{PC}+4=44\),offset 7

\(44+7\times4=72\)

(d)

31題組 C

31. In the next clock cycle (clock cycle 4), what is the instruction being executed in the ID stage? (a) sub $1,$4,$8 (b) beq $1,$3,7 (c) and $12,$2,$5 (d) lw $4,50($7) (e) NOP(同題組 C)

cycle 4 停一拍,beq 原地留在 ID

(b)

32題組 C

32. In the next clock cycle (clock cycle 4), what is the instruction being executed in the EX stage? (a) sub $1,$4,$8 (b) beq $1,$3,7 (c) and $12,$2,$5 (d) lw $4,50($7) (e) NOP(同題組 C)

stall 時 hazard detection unit 把 bubble 灌進 ID/EX,cycle 4 的 EX 什麼都不做

(e)

33題組 C

33. Is there any stall required after the branch is taken (given that Figure 1 shows the pipeline state in clock cycle 3)? (a) No, no required stall after the branch. (b) Yes, one required stall will occur in clock cycle 4 (c) … clock cycle 5 (d) … clock cycle 6 (e) … clock cycle 7(同題組 C)

cycle 4 結束時 beq 在 ID 判定 taken,flush 掉 IF 的 and,cycle 5 起從 72 抓指令:

cycleIFIDEX
3and (44)beqsub
4and (44)beq(stall)NOP
5lw (72)NOP(flush)beq
6add (76)lwNOP
7slt (80)addlw

cycle 7:lw 在 EX、add 在 ID,add 要用 \(\$4\),lw 的資料要等 MEM 才拿得到,forwarding 補不上 → 標準 load-use hazard,再停一拍

停的是 cycle 7(被凍住的 add 與 slt 之後 bubble 在 cycle 8 走到 EX)

(e)

345 分(題組 D:34–38 全對)

D. Assume 4KB pages, a 4-entry two-way set associative TLB and true LRU replacement. If pages must be brought in from disk, increase the next largest page number. Given the virtual address references, and the initial TLB and page table states provided below. Which of following statements is(are) true?

Virtual address references: 4669, 2227, 13916, 34587, 48870, 12608

TLB

SetvalidtagPhysical page number
001112
0136
1174
1049

Page Table(由上而下為 virtual page 0, 1, 2, …, 11)

VPNvalidPhysical page number or in disk
015
10Disk
20Disk
316
419
5111
60Disk
714
80Disk
90Disk
1013
11112

34. For the given address references, list the corresponding virtual page numbers. (a) 0, 0, 0, 2, 2, 0 (b) 1, 0, 3, 0, 3, 3 (c) 1, 0, 3, 8, 11, 3 (d) 0, 0, 1, 4, 5, 1 (e) 1, 0, 1, 0, 1, 1

4 KB = 4096:VPN = 位址 \(\div4096\) 取整

位址4669222713916345874887012608
VPN1038113

(c)

35題組 D

35. For the given address references, the corresponding indexes to the TLB are (a) 0, 0, 0, 2, 2, 0 (b) 1, 0, 3, 0, 3, 3 (c) 1, 0, 3, 8, 11, 3 (d) 0, 0, 1, 4, 5, 1 (e) 1, 0, 1, 0, 1, 1(同題組 D)

4 個 entry、2-way → 2 個 set,index = VPN mod 2

VPN1038113
index101011

(e)

36題組 D

36. For the given address references, the corresponding tags to the TLB are (a) 0, 0, 0, 2, 2, 0 (b) 1, 0, 3, 0, 3, 3 (c) 1, 0, 3, 8, 11, 3 (d) 0, 0, 1, 4, 5, 1 (e) 1, 0, 1, 0, 1, 1(同題組 D)

tag = VPN 去掉最低的 index bit = \(\lfloor\text{VPN}/2\rfloor\)

VPN1038113
tag001451

(d)

37題組 D

37. For the given reference, accesses to TLB are (a) miss, miss, miss, miss, miss, miss (b) miss, hit, miss, miss, miss, miss (c) miss, miss, hit, hit, hit, hit (d) miss, miss, miss, miss, miss, hit (e) miss, hit, hit, miss, hit, hit(同題組 D)

初始 TLB:set 0 有一個無效項(tag 11)與一個有效項(tag 3);set 1 有一個有效項(tag 7)與一個無效項(tag 4);page table 最大的 physical page number 是 12,從 disk 搬進來的 page 依序拿 13、14

#VPNsettagTLBpage table動作
1110missinvalid → page fault配 PPN 13,填 set 1 的無效項
2000missvalid(PPN 5)填 set 0 的無效項
3311missvalid(PPN 6)set 1 已滿,換掉 LRU(tag 7)
4804missinvalid → page fault配 PPN 14,set 0 換掉 LRU(tag 3)
51115missvalid(PPN 12)set 1 換掉 LRU(tag 0,即 VPN 1)
6311hit—上一步沒被換掉

(d)

38題組 D

38. For the given reference, how many page faults in total? (a) None (b) 1 (c) 2 (d) 3 (e) 4(同題組 D)

page table 裡 VPN 1 與 VPN 8 是 invalid(in disk),要從 disk 搬進來;其他存取的 page 都是 valid(VPN 0、3、11)

(c)

109–115 的詳解也是這樣寫的。

國立陽明交通大學 109–115 的詳解收錄在付費版;106–115 全年度完整詳解共 579 頁,逐題推導。

購買 · NT$ 850 看交大其他免費詳解

其他年度與考科

同一年的其他科

同一科的其他年度

聯絡我們

題目有錯、詳解看不懂,都歡迎來信

想許願補哪一份、對購買有疑問也可以,收到後會盡快回覆。

william.chou.123123@gmail.com