复旦大学2007年计算机系统期中考试试题

合集下载
  1. 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
  2. 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
  3. 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。

.L9:
jmp .L6
movl -20(%ebp), %eax
.L7:
leal 0(,%eax,4), %edx
movl -16(%ebp), %eax
movl 20(%ebp), %eax
addl $16, %esp
movl $0, (%eax,%edx)
popl %ebx
movl $0, -24(%ebp)
movl 20(%ebp), %edx
movl -12(%ebp), %eax
addl (%edx,%ecx), %eax
更多免费本科考研试卷 尽在卷卷天下(www.juanjuantx.com)
(1) Assume right after going into the function test (i.e., before the
Problem 2: (20 points)
Fill the following functions. (1*20 points)
Part1 (1*6 points) /* * isLess - if x < y then return 1, else return 0 * Example: isLess(4,5) = 1. * Legal ops: ! ~ & ^ | + << >> * Max ops: 24 * Rating: 3 */ int isLess(int x, int y) {
movl 8(%ebp), %eax
movl (%eax,%edx), %eax
movl %eax, -12(%ebp)
movl -20(%ebp), %eax
leal 0(,%eax,4), %ebx
movl 20(%ebp), %esi
movl -20(%ebp), %eax
leal 0(,%eax,4), %ecx
.L12:
movl $0, -20(%ebp)
leal -24(%ebp), %eax
.L6:
incl
(%eax)
movl -20(%ebp), %eax
jmp .L10
cmpl 12(%ebp), %eax
.L8:
jl
.L9
leal -20(%ebp), %eax
jmp .L7
incl
(%eax)
movl 8(%ebp), %eax
subl $33, %eax
movl %eax, -8(%ebp)
cmpl $7, -8(%ebp)
ja
.L19
movl -8(%ebp), %edx
更多免费本科考研试卷 尽在卷卷天下(www.juanjuantx.com)
movl .L27(,%edx,4), %eax jmp *%eax .section .rodata .align 4 .align 4 .L27: .long .L20 .long .L22 .long .L23 .long .L19 .long .L19 .long .L19 .long .L24 .long .L25 .text .L20: movl 12(%ebp), %eax ______ _[1] _______ ______ _[2]_________ jmp .L19 .L22: movsbl -3(%ebp),%eax movl %eax, 12(%ebp) jmp .L19 .L23: movl $127, 12(%ebp) ______ _ [3]________ jmp .L22 .L24: movl 8(%ebp), %eax ________[4] ________ movl %eax, 12(%ebp) .L25: movl 8(%ebp), %eax ________[5]_________ movl %eax, 12(%ebp) .L19: movw -2(%ebp), %dx movl 12(%ebp), %eax leal (%edx,%eax), %eax movb %al, -3(%ebp) movsbl -3(%ebp),%eax leave ret
} ___[14]___; return ___[15]___; }
x86 assembly code: (3×5 points)
func_switch:
pushl %ebp
movl %esp, %ebp
subl $8, %esp
movw $4, -2(%ebp)
movb $15, -3(%ebp)
(( temp1 >> _[9]_ ) & 0xf ) + (( temp1 >> _[10]_ ) & 0xf ); return result; }
更多免费本科考研试卷 尽在卷卷天下(www.juanjuantx.com)
Problem 3: (30 points)
Fills the blanks in source code and x86 assembly code for func_switch.
short sy = -2; unsigned short usy = sy int y = sy; int x = -31; unsigned ux = x;
Note: You need not fill in entries marked with “---”.
Expression
Decimal Representation
int temp1 = ~ _[1]_; int temp2 = temp1 + 1; int temp3 = x + temp2; int expression1 = x _[2]_ temp1; int expression2 = temp3 _[3]_ ( ~ ( x ^ y )); int ret = ( ( expression1 _[4]_ expression2 ) >> _[5]_ ) & _[6]_ ; return ret; }
Part3 (1*10 points) /*
* Returns a count of the number of 1's in the argument. * Examples: bitCount(5) = 2, bitCount(7) = 3 * Legal ops: ! ~ & ^ | + << >> * Max ops: 40 * Rating: 4 */ int bitCount(int x) {
更多免费本科考研试卷 尽在卷卷天下(www.juanjuantx.com)
Problem 4: (28 points)
Consider the following assembly representation of a function test
test:
movl %eax, (%esi,%ebx)
Source code: (1×15 points) int func_switch(int a, int b){ short s = __[1]___; char c = __[2]___;
switch (___[3]___) { case ___[4]___: s = b - 5; ___[5]___; case ___[6]___:
int temp = ~ x + _[1]_; int temp1 = ( x _[2]_ temp ); int ret = ( _[3]_x ) & ( ! ( _[4]_ + temp1 ) ) & ( ( ~x >> 31 ) & 1 ); return ret; }
更多免费本科考研试卷 尽在卷卷天下(www.juanjuantx.com)
Binary Representation
zero
[1]
[2]
---
-9
[3]
---
[4]
011011
ux
[5]
[6]
y
[7]
[8]
usy
[9]
[10]
x>>1
[11]
[12]
x+y
[13]
[14]
x&!y
[15]
[16]
UMax
[17]
[18]
TMax
[19]
[20]
-TMin
[21]
[22]
更多免费本科考研试卷 尽在卷卷天下(www.juanjuantx.com)
popl %esi
.L10:
leave
movl -24(%ebp), %eax
ret
cmpl 16(%ebp), %eax
jl
.L13
ห้องสมุดไป่ตู้
jmp .L8
.L13:
movl -20(%ebp), %eax
imull 16(%ebp), %eax
addl -24(%ebp), %eax
leal 0(,%eax,4), %edx
pushl %ebp
movl -12(%ebp), %eax
movl %esp, %ebp
cmpl -16(%ebp), %eax
pushl %esi
jle
.L12
pushl %ebx
movl -12(%ebp), %eax
subl $16, %esp
movl %eax, -16(%ebp)
movl $0, -16(%ebp)
Recheck: ___[7]___; ___[8]___;
case ___[9]___: b = 0x7F; a = 0; ___[10]___;
case ___[11]___: b = a * 8;
case ___[12]___: b = a ^ 0xF;
default: ___[13]___;
last instruction of this function. If you do not know the value of some
address, just write down “**” and more reason is preferred (1*12
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 right after the
int common1 = ( _[1]_ << 8) + _[2]_ ; int common = ( common1 << _[3]_ ) + common1; int temp = ( x & common ) + ( ( x >> _[4]_ ) & common ) +
(( x >> _[5]_ ) & common) + (( x >> _[6]_ ) & common ); int temp1 = temp + ( temp >> _[7]_); intresult = ( temp1 & 0xf ) + (( temp1 >> _[8]_ ) & 0xf ) +
Part2 (1*4 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. * Legal ops: ! ~ & ^ | + << >> * Max ops: 60 * Rating: 4 */ int isPower2(int x) {
更多免费本科考研试卷 尽在卷卷天下(www.juanjuantx.com)
Introduction to Computer Systems Fall 2007
Midterm Examination
Name
Student No.
Score
Problem 1: (22 points)
Assume we are running code on a 6-bit machine using two’s complement arithmetic for signed integers. A “short” integer is encoded using 3 bits. Fill in the empty boxes in the table below. The following definitions are used in the table: (1*20 points)
相关文档
最新文档