2021年7月14日 星期三

nand2tetris project5

 本周作業花了不少時間才完成,因此決定寫篇筆記紀錄。

Memory

16384 -> 0100 0000 0000 0000

24576 -> 0110 0000 0000 0000

觀察可知,要區分RAM, Screen與Keyboard,可由13~14bit判斷:

00, 01 -> RAM

10 -> Screen

11 -> Keyboard

跟project3很像,先DMux分配load,之後再Mux

RAM, Screen, Keyboard的規格可以查Hack Chip Set,address根據容量大小而異。


測試時注意:


To anyone facing the same problem… on the Hardware Simulator user interface, right above where you see the script executing the tests, there are three drop down boxes. The one furthest to the right which is labeled “View” is probably currently set to “Script.” Click the drop down and select “Screen,” and you will see an interface that has a keyboard icon. Click it and then hit the corresponding key to complete the test. 

CPU

這部分最困難的是自行分析c,也就是各個元件的控制訊號該怎麼生成。


首先先從Mux16的c開始。我們知道instruction分為A instruction與C instruction,前者是把數字存放進A register,後者是進行運算。因此此處若為A instruction,Mux16就選擇instruction;若為C instruction,Mux16就選擇ALU output。

判斷指令直接看instruction[15]。

同理A register的c也是看instruction[15]。

writeM訊號指的是需不需要write back to memory。

觀察表格後,會發現d1是關鍵。因此若為C instruction且d1為1,則writeM為1,反之為0。

D register同樣觀察表格,發現與d2有關。因此若為C instruction且d2為1,則c為1,反之為0。

第二個Mux16是要選擇A register output或者inM。A instruction選擇前者,C instruction選擇後者這點應該不難理解。這裡需要參考下圖,發現要選A還是M由a,也就是instruction[12]控制。

ALU的c就是C instruction中c的部分。由第 11 bit 依序填入到第 6 bit即可。

最後是PC。沒想法的話就回去看課程網站提供的chip API或是chip的描述:
reset訊號已經有了,inc恆為true,怎麼生成load才是問題。當load==1,代表要把in讀進來,也就是說要jump。那甚麼時候要jump? 當然是條件有達成的時候。
觀察表格會發現,j1代表out < 0條件為真要jump,j2代表out=0條件為真要jump,j3代表out>0條件為真要jump。因此就看: (j1&ng) || (j2&zr) || (j3&(! (ng || zr)) ) 。

沒有留言:

張貼留言