计算机系统要素:第五章 计算机体系结构
来源:互联网 发布:酷狗软件 编辑:程序博客网 时间:2024/05/16 17:28
这篇文章是该书第五章Computer Architecture的解析。这一章结合了前面所有的内容,最终需要我们构建出完整的Computer单元芯片。
在完成这一章的时候,我在调试过程中常常因为一个小错误耽误很久,费很多精力才能把问题解决,所以贴出代码给大家参考,但希望大家不要依赖答案,重要的是搭建CPU和调试中的思考过程。
注:instruction的标号为0到15,其中instruction[15]表示最前面指代A/C指令的一位。
1:CPU.hdl
CHIP CPU { IN inM[16], // M value input (M = contents of RAM[A]) instruction[16], // Instruction for execution reset; // Signals whether to re-start the current // program (reset=1) or continue executing // the current program (reset=0). OUT outM[16], // M value output writeM, // Write into M? addressM[15], // Address in data memory (of M) pc[15]; // address of next instruction PARTS: // Put your code here:Mux16(a=instruction,b=outALU,sel=instruction[15],out=outMux1);//Register A(是否存入A取决于ins[15]与ins[5])Not(in=instruction[15],out=notAnd);<span style="font-family: Arial, Helvetica, sans-serif;"></span>Or(a=notAnd,b=instruction[5],out=outOr);ARegister(in=outMux1,load=outOr,out=outA,out[0..14]=addressM);//DAnd(a=instruction[15],b=instruction[4],out=loadD);DRegister(in=outALU,load=loadD,out=outD);//Mux A&MMux16(a=outA,b=inM,sel=instruction[12],out=outAM);//ALUALU(x=outD,y=outAM,zx=instruction[11],nx=instruction[10],zy=instruction[9], ny=instruction[8], f=instruction[7], no=instruction[6],out=outALU,out=outM,zr=zr,ng=ng);//Mux writeMAnd(a=instruction[3],b=instruction[15],out=writeM);//PC(在判断jump指令时,由于ALU只能生成表示结果为负数或零的两个参数zr、ng,所以还先得到一个表示正数的参数ps,然后将其与jump中的参数相比较,只要有一个参数对应,那么便可以跳转)Not(in=zr,out=notzr);Not(in=ng,out=notng);And(a=notzr,b=notng,out=ps);And(a=ng,b=instruction[2],out=and1);And(a=zr,b=instruction[1],out=and2);And(a=ps,b=instruction[0],out=and3);Or(a=and1,b=and2,out=or1);Or(a=or1,b=and3,out=or2);//禁止A指令时PC采取load行为(非常重要!否则会重复读取指令!)And(a=or2,b=instruction[15],out=outAnd3); PC(in=outAM,load=outAnd3,reset=reset,inc=true,out[0..14]=pc);}
2:Memory.hdl
CHIP Memory { IN in[16], load, address[15]; OUT out[16]; PARTS: // Put your code here:Mux(a=load, b=false, sel=address[14], out=rload); //address[14]=0时,RAM的load有效Mux(a=false, b=load, sel=address[14], out=sload); //address[14]=0时,Screen的load无效RAM16K(in=in, load=rload, address=address[0..13], out=rout);Screen(in=in, load=sload, address=address[0..12], out=sout);Keyboard(out=kout);Mux16(a=sout, b=kout, sel=address[13], out=hout);Mux16(a=rout, b=hout, sel=address[14], out=out);}
3:Computer.hdl
CHIP Computer { IN reset; PARTS: // Put your code here:<span style="white-space:pre"></span>CPU(inM=outM0,instruction=outins,reset=reset,writeM=writeM,outM=outM,addressM=addressM,pc=pc);Memory(in=outM,load=writeM,address=addressM,out=outM0);ROM32K(address=pc,out=outins);}
至此,《计算机系统要素》硬件部分全部结束。从连Nand门是什么都不知道,到亲自动手构建出了Computer芯片,看着一行行01码按着自己的芯片完成指令,这个过程真的超有成就感!可以说种学习体验这胜过我大学所有的计算机课程。也希望所有人都能从学习中收获快乐!
参考资料:
http://blog.csdn.net/tianzhhy/article/details/5807498
《计算机系统要素》一到五章代码
0 0
- 计算机系统要素:第五章 计算机体系结构
- 《计算机系统要素》学习笔记:第五章计算机体系结构
- 计算机系统要素:第十二章 操作系统
- 计算机系统要素:第四章 机器语言
- 计算机系统要素:第八章 虚拟机II 程序控制
- 计算机系统要素:第十章 编译器:语法分析
- 计算机系统要素:第十一章 编译器:代码生成
- 《计算机系统要素》学习笔记:第四章机器语言
- 计算机系统要素:第二章 布尔运算
- 计算机系统要素:第三章 时序逻辑
- 《计算机系统要素》出版!!
- 计算机系统要素 project1
- 《计算机系统要素》概述
- 计算机系统要素:第六章 Part1 汇编编译器(nonsymbol)
- 计算机系统要素:第六章 Part2 汇编编译器(symbol)
- 计算机系统要素:第七章 虚拟机I:堆栈运算
- 《计算机系统要素》学习笔记:第二章布尔运算
- 《计算机系统要素》学习笔记:第三章时序逻辑
- Protocol Buffer简介
- 集成百度语音sdk到智能家居平台中
- android-顺时逆时旋转的仪表盘控件
- 2014年8月18日 聚焦互联网金融
- Android中的ListView用法(自动滚动)
- 计算机系统要素:第五章 计算机体系结构
- POJ 2965 The Pilots Brothers' refrigerator(dfs+记录路径)
- axis 开发webservice
- PHP里$_SERVER['HTTP_HOST']和$_SERVER['PHP_SELF']区别
- C float类型 范围 详解
- TQ2440 在Keil V5 MDK下创建工程 并 使用Jlink 在RAM调试 方法
- ORACLE11g 区的管理与分配
- Openstack rootwrap
- 数据库规范