ImageVerifierCode 换一换
格式:DOCX , 页数:18 ,大小:18.45KB ,
资源ID:5483027      下载积分:3 金币
快捷下载
登录下载
邮箱/手机:
温馨提示:
快捷下载时,用户名和密码都是您填写的邮箱或者手机号,方便查询和重复下载(系统自动生成)。 如填写123,账号就是123,密码也是123。
特别说明:
请自助下载,系统不会自动发送文件的哦; 如果您已付费,想二次下载,请登录后访问:我的下载记录
支付方式: 支付宝    微信支付   
验证码:   换一换

加入VIP,免费下载
 

温馨提示:由于个人手机设置不同,如果发现不能下载,请复制以下地址【https://www.bdocx.com/down/5483027.html】到电脑端继续下载(重复下载不扣费)。

已注册用户请登录:
账号:
密码:
验证码:   换一换
  忘记密码?
三方登录: 微信登录   QQ登录  

下载须知

1: 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。
2: 试题试卷类文档,如果标题没有明确说明有答案则都视为没有答案,请知晓。
3: 文件的所有权益归上传用户所有。
4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
5. 本站仅提供交流平台,并不能对任何下载内容负责。
6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

版权提示 | 免责声明

本文(计算机结构与组成cpu仿真.docx)为本站会员(b****3)主动上传,冰豆网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对上载内容本身不做任何修改或编辑。 若此文所含内容侵犯了您的版权或隐私,请立即通知冰豆网(发送邮件至service@bdocx.com或直接QQ联系客服),我们立即给予删除!

计算机结构与组成cpu仿真.docx

1、计算机结构与组成cpu仿真 Project 1一问题描述: 这个工程需要编写MIPS汇编语言一个子集的指令解释器. 它将实现取指、反汇编, 解码, 并执行MIPS机器指令。也就是构建一个缩微的MARS。二问题分析:老师已经给出了一个工程,要求我们在所给文件中添加相应的代码,使sample.dump中的机器码(也就是一串数字)可以实现反汇编,在控制台黑屏中输出汇编指令和寄存器及内存的更新情况。而且.cpp文件中提供了两个函数disassembled和simulateInstr来分别实现上述功能。反汇编说明:在disassembled函数中,我要将数字指令转化为汇编语言,这首先需要对一段数字进行分

2、割,如先取32位数字的前6位为其opcode段等,数字分割是通过左移和右移实现的,具体代码如下:int opcode,func,rs,rt,rd,shamt,targaddress,immediate; opcode=instr26; rs=(instr27; rt=(instr27; rd=(instr27; shamt=(instr27; func=(instr26; immediate=(instr16; targaddress=(instr6; 完成数字分割后,就进入具体的指令分析阶段,此步通过if-else语句实现。如先解析R格式语句,先选出opcode为0的32为指令数字段,再针对

3、具体的func的值为其对上不同的汇编指令,例如opcode=0,func=33表示addu指令:if(opcode=0) if(func=33) /addu strcat_s(result1,addu $); strcat_s(result,result1); _itoa_s(rd,temp,10); strcat_s(result,temp); strcat_s(result, $); _itoa_s(rs,temp,10); strcat_s(result,temp); strcat_s(result, $); _itoa_s(rt,temp,10); strcat_s(result,te

4、mp); 运用strcat函数实现字符串的拼接,itoa_s函数将二进制数变为其他进制数输出,结果便可在黑频上输出如下类似指令: addu $0, $2, $2将所有情况的不同opcode和func的值用if-else语句像上面这样表示出来,于是就可以将所有的32位指令数字段解码成汇编代码,但此时的代码只是个空壳而已,需要用下面的simulateInstr函数将不同的指令的pc改变,计算,寄存器和内存的更新表示出来。在simulateInstr函数中同样也需要对每个32位指令数字段进行划分然后依据不同的opcode和func设置pc,进行计算以及表示寄存器和内存是否被更新 。在这里,寄存器及内

5、存的是否更新使用数字表示,-1代表没有更新,例如addu:if(opcode=0) if(func=33) /addu mips-pc = mips-pc + 4; mips-registersrd=mips-registersrt+mips-registersrs; if(rd=0) rd=-1; *changedReg = rd; *changedMem = -1; 其中pc会顺序加4,内存没有改变,但addu所加的结果被存在rd寄存器中,所以rd寄存器会更新。 将所有指令的实质改变按此方法用if-else语句表示出来后,该工程也就完成了。三所遇问题及改进方案: (1)在编程过程中,我开始

6、不知道该怎么样实现数据的符号扩展,因为我对32位数据采用的是左移右移方法来实现指令分割的,这就相对于对所有字段都进行的是零扩展,这对于addi,lw,sw指令中需要进行符号扩展的立即数来说显然矛盾。后来,在请教同学的基础上,我改进了方法,对于那些只需做零扩展的立即数,不需要做什么改变。对与addi这类需做符号扩展的立即数,我在相应的if语句中对立即数进行判断,如果立即数小于32768(也就是2的15次方),也就是该立即数的第一位数是0,那么零扩展与符号扩展对该立即数的真实值无影响,也就不需改变什么;反之,则该立即数的第一位数是1,那么必须进行符号扩展,即将该立即数减去65536(2的16次方)

7、即可。例如sw:if(opcode=43) /sw strcat_s(result1,sw $); strcat_s(result,result1); _itoa_s(rt,temp,10); strcat_s(result,temp); strcat_s(result, ); if(immediate26; rs=(instr27; rt=(instr27; rd=(instr27; shamt=(instr27; func=(instr26; immediate=(instr16; targaddress=(instr6; if(opcode=0) if(func=35) /subu st

8、rcat_s(result1,subu $); strcat_s(result,result1); _itoa_s(rd,temp,10); strcat_s(result,temp); strcat_s(result, $); _itoa_s(rs,temp,10); strcat_s(result,temp); strcat_s(result, $); _itoa_s(rt,temp,10); strcat_s(result,temp); if(func=33) /addu strcat_s(result1,addu $); strcat_s(result,result1); _itoa_

9、s(rd,temp,10); strcat_s(result,temp); strcat_s(result, $); _itoa_s(rs,temp,10); strcat_s(result,temp); strcat_s(result, $); _itoa_s(rt,temp,10); strcat_s(result,temp); if(func=36) /and strcat_s(result1,and $); strcat_s(result,result1); _itoa_s(rd,temp,10); strcat_s(result,temp); strcat_s(result, $);

10、 _itoa_s(rs,temp,10); strcat_s(result,temp); strcat_s(result, $); _itoa_s(rt,temp,10); strcat_s(result,temp); if(func=37) /or strcat_s(result1,or $); strcat_s(result,result1); _itoa_s(rd,temp,10); strcat_s(result,temp); strcat_s(result, $); _itoa_s(rs,temp,10); strcat_s(result,temp); strcat_s(result

11、, $); _itoa_s(rt,temp,10); strcat_s(result,temp); if(func=42) /slt strcat_s(result1,slt $); strcat_s(result,result1); _itoa_s(rd,temp,10); strcat_s(result,temp); strcat_s(result, $); _itoa_s(rs,temp,10); strcat_s(result,temp); strcat_s(result, $); _itoa_s(rt,temp,10); strcat_s(result,temp); if(func=

12、0) /sll strcat_s(result1,sll $); strcat_s(result,result1); _itoa_s(rd,temp,10); strcat_s(result,temp); strcat_s(result, $); _itoa_s(rt,temp,10); strcat_s(result,temp); strcat_s(result, ); _itoa_s(shamt,temp,10); strcat_s(result,temp); if(func=2) /srl strcat_s(result1,srl $); strcat_s(result,result1)

13、; _itoa_s(rd,temp,10); strcat_s(result,temp); strcat_s(result, $); _itoa_s(rt,temp,10); strcat_s(result,temp); strcat_s(result, ); _itoa_s(shamt,temp,10); strcat_s(result,temp); if(func=8) /jr strcat_s(result1,jr $); strcat_s(result,result1); _itoa_s(rs,temp,10); strcat_s(result,temp); if(opcode=9)

14、/addiu strcat_s(result1,addiu $); strcat_s(result,result1); _itoa_s(rt,temp,10); strcat_s(result,temp); strcat_s(result, $); _itoa_s(rs,temp,10); strcat_s(result,temp); strcat_s(result, ); if(immediate=32768) immediate-=65536; pc=pc+4+immediate*4; _itoa_s(pc,temp,16); strcat_s(result,temp); if(opcod

15、e=5) /bne strcat_s(result1,bne $); strcat_s(result,result1); _itoa_s(rs,temp,10); strcat_s(result,temp); strcat_s(result, $); _itoa_s(rt,temp,10); strcat_s(result,temp); strcat_s(result, 0x); if(immediate=32768) immediate-=65536; pc=pc+4+immediate*4; _itoa_s(pc,temp,16); strcat_s(result,temp); if(op

16、code=35) /lw strcat_s(result1,lw $); strcat_s(result,result1); _itoa_s(rt,temp,10); strcat_s(result,temp); strcat_s(result, ); if(immediate32768) _itoa_s(immediate,temp,10); else _itoa_s(immediate-65536,temp,10); strcat_s(result,temp); strcat_s(result,($); _itoa_s(rs,temp,10); strcat_s(result,temp);

17、 strcat_s(result,); if(opcode=43) /sw strcat_s(result1,sw $); strcat_s(result,result1); _itoa_s(rt,temp,10); strcat_s(result,temp); strcat_s(result, ); if(immediate28)28)+(targaddress4); strcat_s(result1,j 0x); strcat_s(result,result1); _itoa_s(pc,temp,16); strcat_s(result,temp); if(opcode=3) /jal p

18、c=(pc+4)28)28)+(targaddress4); strcat_s(result1,jal 0x); strcat_s(result,result1); _itoa_s(pc,temp,16); strcat_s(result,temp); return result;void simulateInstr (Computer mips, unsigned int instr, int *changedReg, int *changedMem) /* You replace this code by the right stuff. */ int opcode,func,rs,rt,

19、rd,shamt,targaddress,immediate; opcode=instr26; rs=(instr27; rt=(instr27; rd=(instr27; shamt=(instr27; func=(instr26; immediate=(instr16; targaddress=(instr6; if(opcode=0) if(func=33) /addu mips-pc = mips-pc + 4; mips-registersrd=mips-registersrt+mips-registersrs; if(rd=0) rd=-1; *changedReg = rd; *

20、changedMem = -1; if(func=35) /subu mips-pc = mips-pc + 4; mips-registersrd=mips-registersrs+mips-registersrt; if(rd=0) rd=-1; *changedReg = rd; *changedMem = -1; if(func=36) /and mips-pc = mips-pc + 4; mips-registersrd=mips-registersrs&mips-registersrt; if(rd=0) rd=-1; *changedReg = rd; *changedMem

21、= -1; if(func=37) /or mips-pc = mips-pc + 4; mips-registersrd=mips-registersrs|mips-registersrt; if(rd=0) rd=-1; *changedReg = rd; *changedMem = -1; if(func=42) /slt mips-pc = mips-pc + 4; if(mips-registersrsregistersrt) mips-registersrd=1; else mips-registersrd=0; if(rd=0) rd=-1; *changedReg = rd; *changedMem = -1; if(func=0) /

copyright@ 2008-2022 冰豆网网站版权所有

经营许可证编号:鄂ICP备2022015515号-1