《深入理解计算机系统》第3章家庭作业

3.58

long decode2(long x,long y,long z){
	y=y-z;
	x=x*y;
	result = (y<<63)>>63;
	result = result^x;
	return result;
} 

3.60

A:
	%rdi保存x,%esi保存n,%rdx保存mask,%rax保存result
B:
	result = 0;
	mask = 1;
C:
	mask != 0
D:
	mask = (mask << n)
E:
	 result |= (x & mask)
F:
long loop(long x, int n){
    long result = 0;
    long mask;
    
    for (mask = 1; mask != 0; mask = mask << n){
        result |= (x & mask);
    }
    
    return result;
}

3.63

long switch_prob(long x, long n){
    switch(n){
        
    case 60: 
        
    case 62: 
    		 result = x * 8;
             break;
                 
    case 63: 
    		 result = x;
    		 result = result >> 3;
             break;

    case 64: 
    		 result = x;
    		 result = (result << 4) - x;
             x = result;
             
    case 65: x = x * x;
                 
    default: result = x + 0x4b;
    }
    return result;
}

3.69

A. last的偏移量为0x120,即first和a[CNT]占288字节

​ bp+40i+8->%rdx,即first占8字节,数组a元素的偏移量为40字节

​ CNT = (288-8)/40 = 7

B. %rcx-> ap*8 + ap +8,即idx占8字节

a_struct{
	long idx;
	int x[?];
}

3.70

A. e1.p 0

​ e1.y 8

​ e2.x 0

​ e2.next 8

B. 16

C.

up->e1.p = *(*(up->e2.next).e1.p)-*(up->e2.next).e1.y;
  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值