根据c代码和对应生成的汇编代码推断:
A.CNT的值。
B.结构a_struct的完整声明,假设这个结构只有字段idx和x,并且都为有符号值。
typedef struct{
int first; //0+4
a_struct a[CNT]; //8+280
int last; //288+4
}b_struct
void test(long i,b_struct *bp){
int n = bp->first +bp->last;
a_struct *ap = &bp->a[i];
ap-x[ap-idx] = n;
}
汇编代码:
mov 0x120(%rsi),%ecx //##%ecx = %rsi+0x120 //last偏移量288
add (%rsi),%ecx //##%ecx =%ecx+%rsi // first+last = n
lea (%rdi,%rdi,4),%rax //##%rax=5rdi
lea (%rsi,%rax,8),%rax //##%rax = (5rdi)*8+rsi //%rax = bp+40i //每个a[i]的大小是40
mov 0x8(%rax),%rdx //##%rdx = M[8+bp+40i] //因为只有这一个取内存的操作,所以%rdx =ap->idx的值,从偏移为8能看出first占用8字节,有a_struct的总大小为288-8字节,8位对齐,ap=8+bp+40i //CNT =