版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
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. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- ISO9001-2026《质量管理体系-要求》(正式版)之“8.5.2标识和可追溯性”条款专题深度解读与专业应用操作指南(2026A0-雷泽佳编制)
- 散打教练岗位教学考试试卷及答案
- 中继泵站运行工岗前理论知识考核试卷含答案
- 电机铁芯叠装工变革管理模拟考核试卷含答案
- 货车检车员改进能力考核试卷含答案
- 己二酸装置操作工发展趋势考核试卷含答案
- 品酒师岗中应急考核试卷含答案
- 2026年生物安全培训试题(含答案)
- 2026年生产计划员试题(附答案)
- 乳品加工工岗位综合评估考核试卷含答案
- 公立医院领导人员管理办法-2017-2026完整对比版
- 2027届上海市浦东新区洋泾中学物理高二上期中考试试题含解析
- 2026重庆渝中区社区工作者及后备人员招聘《综合知识》模拟试卷
- 《10 谁在运动》课件2026-2027学年湘科版四年级上册科学
- 医疗机构麻醉药品和精神药品管理规定2026解读
- 《中华人民共和国生态环境法典》测试题(含参考答案)
- 【新教材】2026年秋人教版(PEP)五年级上册英语全册教案(含教学计划)
- DBJ50-T-061-2021 预拌砂浆生产与应用技术标准
- 2026语文新教材 7.我的战友邱少云 课件
- 电子科技大学学生手册
- 基于QFD创新型品管圈的区域药学服务新模式构建(药剂科)(药房)(门诊)(药房门诊)
评论
0/150
提交评论