学び直し27日目第二ラウンド:5章 コンピュータアーキテクチャ⑧:プロジェクト-Computer(5章終了)
記録
Memory と CPU ができたので、いよいよ Computer の HDL を実装した。拍子抜けするくらい簡単だったw。部品をきちんと用意できれば、コンピュータは簡単につくれるのだなぁ。けっこう時間かかったけど、楽しかった。HDL 書きたい。FPGA 使ってみたい。
Computer
// This file is part of www.nand2tetris.org // and the book "The Elements of Computing Systems" // by Nisan and Schocken, MIT Press. // File name: projects/05/Computer.hdl /** * The HACK computer, including CPU, ROM and RAM. * When reset is 0, the program stored in the computer's ROM executes. * When reset is 1, the execution of the program restarts. * Thus, to start a program's execution, reset must be pushed "up" (1) * and "down" (0). From this point onward the user is at the mercy of * the software. In particular, depending on the program's code, the * screen may show some output and the user may be able to interact * with the computer via the keyboard. */ CHIP Computer { IN reset; PARTS: // Put your code here: CPU( inM=inM, instruction=instruction16, reset=reset, outM=outM16, writeM=outwriteIntoM, addressM=outAddressM15, pc=outPc15 ); Memory(in=outM16, load=outwriteIntoM, address=outAddressM15, out=inM); ROM32K(address=outPc15, out=instruction16); }
5章おさらい
- 機械語の仕様を理解できれば、ハードウェアの実装は割と容易。裏を返すと、ハードウェアは機械語の仕様に合わせて作られる。
- 機械語による命令には、A 命令と C 命令がある。A 命令はメモリアドレスや定数を A レジスタに読み込むための命令。C 命令は A レジスタ、D レジスタ、ALU を使って演算したり、PC の操作(inciment や jump)する命令。これら命令の各bitの意味を理解できれば、CPU の設計は割と容易(だけど根気がないとアカン)。
- メモリマップドI/Oを通じて、メモリマップの概念を理解できた。いじり方は RAM と同じだけど、いじる場所に応じて IO の操作や入力受付ができる。RAM 領域と I/O 領域を排他的に定義したもの、ざっくりいうと、どこをいじると何ができるのか定義したものがメモリマップ。
今日の筋トレ
酒飲んじゃったのでおやすみ。