CSAPP_Chapter_3_程序的机器级表示_HW

题3.58
long decode2(long x, long y, long z) {
    long result = 0;
    x = x * (y - z);
    result = ((x << 63) >> 63) ^ x;

    return result;
}
题3.60
long loop(long x, int n) {
    long result = 0;
    long mask;
    for (mask = 1; mask != 0; mask <<= n) {
        result |= (x & mask);
    }
    return result;
}
题3.68

A=9,B=5

题3.70
// A. 0; 8; 0; 8

// B. 16字节

// C. 代码如下: 
union ele {
    struct {
        long* p;
        long y;
    }e1;
    struct {
        long x;
        union ele* next;
    }e2;
};

void proc(union ele* up) {
    up->e2.x = *(up->e2.next->e1.p) - up->e2.next->e1.y;
}
题3.71
#include <stdio.h>
#define BUFSIZE 64

void good_echo() {
    char buf[BUFSIZE];
    int i;

    while (1) {
        if (!fgets(buf, BUFSIZE, stdin)) return;
        for (i = 0; buf[i] && buf[i] != '\n'; i++)
            if (putchar(buf[i]) == EOF) return;
        if (buf[i] == '\n') {
            putchar('\n');
            return;
        }
    }
}

int main() {
    good_echo();

    return 0;
}

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值