。
(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
。
1
。
leave
ret
根据以上的汇编代码,完成相应的 for 循环 C程序代码 ( 注意该程序有返回值 ) 。
int looper(int n, int *a)
{
int i;
int x=0;
for(i= 0 ; i
{______________________________________
if(a[i]>x)//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 {