复旦大学计算机体系结构考试,复旦大学计算机体系结构期末考试B卷

a7f4a3f590493a1e451dd952a488fd7c.gif 复旦大学计算机体系结构期末考试B卷

(15页)

0ae7f30e54d6b0933871fcfd39cff563.gif

本资源提供全文预览,点击全文预览即可全文预览,如果喜欢文档就下载吧,查找使用更方便哦!

9.90 积分

(1)考虑下面这个for循环的汇编代码looper: pushl %ebp movl %esp, %ebp subl $16, %esp movl $0, -8(%ebp) movl $0, -4(%ebp) jmp .L2.L4: movl -4(%ebp), %eax sall $2, %eax addl 12(%ebp), %eax movl (%eax), %eax cmpl -8(%ebp), %eax jle .L3 movl -4(%ebp), %eax sall $2, %eax addl 12(%ebp), %eax movl (%eax), %eax movl %eax, -8(%ebp).L3: addl $1, -8(%ebp) addl $2, -4(%ebp).L2: movl -4(%ebp), %eax cmpl 8(%ebp), %eax jl .L4 movl -8(%ebp), %eax leave ret根据以上的汇编代码,完成相应的for循环C程序代码(注意该程序有返回值)。int looper(int n, int *a){ int i; int x=0;for(i= 0 ; ix)//2分 x=a[i];// 2分 x++;//1分 }______________________________________return x;// 1分 }(2)根据已有的结构(structure)和联合(union)的声明以及C函数void test(int i, s2 *bp)的IA32 汇编代码,推断出结构s1的完整声明和s2中CNT的值;之后再根据推断结果以及IA32汇编代码,推断补齐相应的C程序代码。下面是要使用到的结构和联合的声明,函数void test(int i, s2 *bp)及其IA32 汇编代码。struct s1 { struct s2 { union u1 { int left; struct s1 *h; s1 a[CNT]; struct s2 *i; int right; char j; }; union u1 b; }; char c; }; void test(int i, s2 *bp){ int n=bp->left+bp->right; s1 *ap=&bp->a[i]; ap->x[ap->idx]=n;}其IA32汇编代码为:test: pushl %ebp movl %esp, %ebp subl $16, %esp movl 12(%ebp), %eax movl (%eax), %edx movl 12(%ebp), %eax movl 184(%eax), %eax leal (%edx,%eax), %eax movl %eax, -4(%ebp) movl 12(%ebp), %eax leal 4(%eax), %ecx movl 8(%ebp), %edx movl %edx, %eax sall $2, %eax addl %edx, %eax sall $2, %eax leal (%ecx,%eax), %eax movl %eax, -8(%ebp) movl -8(%ebp), %eax movl (%eax), %edx movl -8(%ebp), %eax movl -4(%ebp), %ecx movl %ecx, 4(%eax,%edx,4) leave ret1. CNT=___9_____//2分2. 写出s1的完整声明。____struct s1{ int idx;//2分 int x[4];//2分 ___}___________________________________________________________________________ _______________________________________3. 对于下面左边的每个IA32 汇编代码,请在右边补全相应的C程序代码。(请注意下面的函数都需要返回值)A. proc1: pushl %ebp movl %esp, %ebp movl 8(%ebp), %eax movzbl 188(%eax), %eax popl %ebp retchar proc1(struct s2 *x){______________________________return x->b.j;(4分)__________________________________________________________________________________________}B. proc2: pushl %ebp movl %esp, %ebp subl $16, %esp movl 8(%ebp), %eax movl 188(%eax), %eax movl (%eax), %eax movl %eax, -4(%ebp) movl 8(%ebp), %eax movl 188(%eax), %eax movl 184(%eax), %eax addl %eax, -4(%ebp) movl -4(%ebp), %eax leave retC. proc3: pushl %ebp movl %esp, %ebp subl $16, %esp movl 8(%ebp), %eax movl (%eax), %eax movl 188(%eax), %eax movzbl 192(%eax), %eax movb %al, -1(%ebp) movl 8(%ebp), %eax movl (%eax), % 关 键 词: 复旦大学 计算机体系结构 期末考试

4d91c43bfc72ca913299809b07b4968f.gif  天天文库所有资源均是用户自行上传分享,仅供网友学习交流,未经上传用户书面授权,请勿作他用。

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值