版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
1、Introduction to Computer Systems Fall 2007Midterm ExaminationNameStudent No.ScoreProblem 1: (22 points)Assume we are running code on a 6-bit machine using twos complement arithmetic for signed integers. A “short” integer is encoded using 3 bits.Fill in the empty boxes in the table below. The followi
2、ng definitions areshort sy = -2;unsigned short usy = sy int y = sy;int x = -31; unsigned ux = x;used in the table: (1*20 points)Bina Represe230110681012141618202221-TMin19TMax17UMax15x&!y13x+y11x19usy7y5ux4-9-1zeroDecimal RepresentationExpressionNote: You need not fill in entries marked with “-”.卷卷天
3、下卷卷天下Problem 2: (20 points)Fill the following functions. (1*20 points)/* isLess - if x ythen return 1, else return 0* Example: isLess(4,5) = 1.* Legal ops: ! & | + * Max ops: 24* Rating: 3*/int isLess(int x, int y)int temp1 = _1_; int temp2 = temp1 + 1; int temp3 = x + temp2;int expression1 = x_2_ t
4、emp1;int expression2 = temp3 _3_ ( ( x y );int ret = ( ( expression1 _4_ expression2 ) _5_ ) & _6_ ; return ret;Part1 (1*6 points)/* Returns 1 if x is a power of 2 and x 0, otherwise return 0* Examples: isPower2(5) = 0, isPower2(8) = 1, isPower2(0) = 0* Note that no negative number is a power of 2.*
5、 Legal ops: ! & | + * Max ops: 60* Rating: 4*/int isPower2(int x)int temp = x + _1_;int temp1 = ( x _2_ temp );int ret= ( _3_x ) & ( ! ( _4_ + temp1 ) ) & ( ( x 31 ) & 1 ); return ret;Part2 (1*4 points)/* Returns a count of the number of 1s in the argument.* Examples: bitCount(5) = 2, bitCount(7) =
6、3* Legal ops: ! & | + * Max ops: 40* Rating: 4*/int bitCount(int x)int common1 = ( _1_ 8) + _2_ ;int common = ( common1 _4_ ) & common ) +( x _5_ ) & common) +( x _6_ ) & common ); int temp1 = temp + ( temp _7_);intresult = ( temp1 & 0xf ) + ( temp1 _8_ ) & 0xf ) +( temp1 _9_ ) & 0xf ) + ( temp1 _10
7、_ ) & 0xf ); return result;Part3 (1*10 points)nc_switch:ushl %ebpovl %esp, %ebp bl $8, %espovw $4, -2(%ebp)notvbfu$n1c5_,s-w3(i%tcheb(ipn)t a, int b) ovshl o8r(t%se=bp), %1eax ; bcl h$a3r3c, =%eax2;ovl %eax, -8(%ebp)mpslw$it7c,h-(8(%eb3p) .cLa1s9e4:Problem 3: (30 points)Fills the blanks in source co
8、de and x86 assembly code for func_switch.Source code: (115 points)x86 assembly code: (35 points)ovl -s8(=%beb-p5);, %edxovl .L27(,5%edx,;4), %eaxp c*a%seeax6:Reecctihoenck.r:odatalign 4ign 47;8;7:case9: ong .bL2=0 0x7F;ong .aL2=2 0;ong .L2310;ongca.Lse1911:ong .bL1=9 a * 8;ongca.Lse1912:ong .bL2=4 a
9、 0xF; ongde.Lfa2u5lt:ext13; 0:ovl 121(%4ebp),; %eax return_1 15;_2 p .L192:ovsbl -3(%ebp),%eax ovl %eax, 12(%ebp) p .L193:ovl $127, 12(%ebp)_ 3 p .L22 4:ovl 8(%ebp), %eax4 ovl %eax, 12(%ebp) 5:ovl 8(%ebp), %eax5 ovl %eax, 12(%ebp) 9:ovw -2(%ebp), %dxProblem 4: (28 points)Consider the following assem
10、bly representation of a function testtest:pushl %ebpmovl %esp, %ebp pushl %esipushl %ebx subl $16, %espmovl $0, -16(%ebp) movl $0, -20(%ebp).L6:movl -20(%ebp), %eax cmpl 12(%ebp), %eax jl.L9jmp.L7.L9:movl -20(%ebp), %eax leal0(,%eax,4), %edx movl 20(%ebp), %eax movl $0, (%eax,%edx) movl $0, -24(%ebp
11、).L10:movl -24(%ebp), %eax cmpl 16(%ebp), %eax jl.L13jmp.L8.L13:movl -20(%ebp), %eax imull 16(%ebp), %eax addl -24(%ebp), %eax leal0(,%eax,4), %edx movl 8(%ebp), %eax movl (%eax,%edx), %eax movl %eax, -12(%ebp) movl -20(%ebp), %eax leal0(,%eax,4), %ebx movl 20(%ebp), %esi movl -20(%ebp), %eax leal0(
12、,%eax,4), %ecx movl 20(%ebp), %edx movl -12(%ebp), %eax addl (%edx,%ecx), %eaxmovl %eax, (%esi,%ebx) movl -12(%ebp), %eax cmpl -16(%ebp), %eax jle.L12movl -12(%ebp), %eax movl %eax, -16(%ebp).L12:leal-24(%ebp), %eax incl(%eax)jmp.L10.L8:leal-20(%ebp), %eax incl(%eax)jmp.L6.L7:movl -16(%ebp), %eax ad
13、dl $16, %esppopl %ebx popl %esi leaveret(1)Assume right after going into the function test (i.e., before the instruction “pushl %ebp”), the value of %ebp is 0xbffff9A4 and the value of %esp is 0xbffff62C. Fill the following table with the values stored at the indicated memory addresses and registers
14、 right after the last instruction of this function. If you do not know the value of some address, just writeAddressValue0xbffff61010xbffff61420xbffff61830xbffff61C40xbffff62050xbffff62460xbffff62870xbffff62C0x804592c0xbffff6300x804A92c0xbffff6340x40xbffff6380x30xbffff63C0x804A9640xbffff6400x804A9300
15、x 804A97080x 804A96C90x 804A968100x 804A964110x 804A960120x 804A95C0x80x 804A9580x250x 804A9540x1D0x 804A9500x470x 804A94C0x350x 804A9480x2E0x 804A9440x200x 804A9400x160x 804A93C0xb0x 804A9380x80x 804A9340x230x 804A9300x180x 804A92c0x10down “*” and more reason is preferred (1*12 points)LabelThe nute
16、st.L6.L9.L10.L13.L12.L8.L7(2)How many times does this function read or write the value of certain memory address when executing with the given values? (Assume executing incl (%eax) once, referencing memory twice). Note: Explain the procedure asdetailed as possible, for example, how many times does e
17、ach instruction execute and you can mark it on the right ofthe instruction and show why, and furthermore, you can list the numbers of these 8 label, such as, .L6 * and so on. (28 points)Solution:DecimalRepresentationBinaryProblem 1: (22points 1*22)Problem 2: (20points)1.(1*6points)(1)(2)(3)(4)(5)(6)2. (1*4 points)(1)(2)(3)(4)3
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 2026年张家界市中考冲刺卷化学试题(含答案解析)
- 卧床病人皮肤清洁与干燥技巧
- 初中八年级地理教学设计:海洋国土的蓝色沃土
- 动态循环持续改进:护理PDCA
- 机修钳工问答试题及答案
- 初中八年级历史上册《甲午之痛与民族觉醒》教学设计
- 带教过程中的反馈与激励技巧
- Unit8Section4课件沪教版七年级英语下册
- 时间在哪里小讲堂课件-人教版二年级下册数学
- 主题六探寻一带一路沿线地区(期末复习课件)七年级地理下学期新教材晋教版
- 设备点检员三级-高级理论知识试卷(B)
- 医院年度审计报告
- 不同温度下饱和蒸汽压力及水含量对照表
- 固定资产管理台账折旧、盘点登记表
- 临床麻醉学考试试题
- 2023北京朝阳区初一期末(下)历史试卷及答案
- EPC工程总承包项目组织机构岗位设置
- 船舶电喷柴油机瓦锡兰共轨技术演示文稿
- 二年级下学期语文无纸化测试题例
- 律师会见笔录模板及律师会见笔录模板(官方版)
- 工程光学:实验六、阿贝成像原理和空间滤波实验
评论
0/150
提交评论