Skip to content
This repository has been archived by the owner on Oct 8, 2022. It is now read-only.

Latest commit

 

History

History
566 lines (505 loc) · 10.2 KB

1600013006.md

File metadata and controls

566 lines (505 loc) · 10.2 KB

这是我的作业 第九次作业 10.8 void sigchild_handle(int sig) { while(waitpid(-1, NULL, 0) > 0) }

在main函数中添加 signal(SIGCHLD,sigchld_handler);

在server_dynamic中删去Wait(NULL);

10.9 srcfd = Open(filename, O_RDONLY, 0); srcp = (char *)malloc(filesize * sizeof(char)); Rio_readn(srcfd, srcp, filesize); close(srcfd); Rio_writen(fd, srcp, filesize); Free(srcp);

第九次作业反馈

第一题:有误
第二题:正确

第八次作业 #include <assert.h> #include <stdio.h> #include <stdlib.h> #include <unistd.h> #include <string.h> #include <setjmp.h> #include <ctype.h> #include <signal.h> #include <sys/types.h> #include <fcntl.h> #include <sys/wait.h> #include <errno.h> jmp_buf env; void unix_error(char *msg) { fprintf(stdout, "%s: %s\n", msg, strerror(errno)); exit(1); } typedef void handler_t(int); handler_t *Signal(int signum, handler_t handler); handler_tSignal(int signum, handler_t *handler) { struct sigaction action, old_action;

action.sa_handler = handler;
sigemptyset(&action.sa_mask); /* block sigs of type being handled */
action.sa_flags = SA_RESTART; /* restart syscalls if possible */

if (sigaction(signum, &action, &old_action) < 0)
	unix_error("Signal error");
return (old_action.sa_handler);

} //以上部分从lab中复制得 void sigsegv_handler(int sig) { siglongjmp(env, 1);//如果段错误,回到原先的位置,并返回1 } int main() { Signal(SIGSEGV, sigsegv_handler); char a; char * visit = (char *)0x400000l; long add = 4096; while ((long)visit < (1lu << 63)) { switch (sigsetjmp(env, 1))//观测返回值,判断是否可读 { case 0: { a = *visit; printf("0x%lx\n", (long)visit >> 12); break; } default: { break; } } visit += add; } return 0; } //把虚拟地址空间从头到尾遍历一遍

第七次作业

8.9 进程对 并发地? AB 否 AC 是 AD 是 BC 是 BD 是 CD 是

8.18 ACE 8.24

#include"csapp.h" #define N 2 int main() { int status, i; pid_t pid;

for (i = 0; i < N; i++)
{
	if ((pid = Fork()) == 0)
		exit(100 + i);
}

while ((pid = waitpid(-1, &status, 0)) > 0)
{
	if (WIFSIGNALED(status))
	{
		if (WTERMSIG(status) == 11)
		{
			printf("child %d terminated by signal 11: Segmentation fault", pid);
		}
	}
}

if (errno != ECHILD)
	unix_error("waitpid error");

exit(0);

}

10.6 4 10.9 if (infile) { int fd3 = open(infile, O_RDONLY, 0); dup2(fd3, atoi(argv[1])); }

第七次作业反馈

第一题:正确
第二题:正确
第三题:错误
第四题:正确
第五题:有误

第六次作业 7.6 符号 Swap.o.symtab条目 符号类型 定义符号的模块 节 buf 是 外部 m.o .data bufp0 是 全局 swap.o .data bufp1 是 全局 swap.o .bss swap 是 全局 swap.o .text temp - - - - incr 是 全局 swap.o .text count 是 局部 swap.o .bss

7.7 /* bar5.c */ double x;

void f() {

}

7.12 A: 0xa B: 0x22

7.13 A: libc.a 1579 libm.a: 471 B: 不同,-g有debug节和line节 C: linux-vdso.so.1 libc.so.6 ld-linux-x86-64.so.2

第六次作业反馈

第一题:有一处错误
第二题:正确
第三题:正确
第四题:正确

第五次作业 4.47 A: void bubble_a(long *data, long count) { long i, last; for (last = count - 1; last > 0; last++) { for (i = 0; i < last; i++) { long t = *(data + i + 1); *(data + i + 1) = *(data + i); *(data + i) = t; } } }

B: bubble_a: pushl %ebp pushl %ebx movl %esp, %ebp movl %edi, -40(%ebp) movl %esi, -48(%ebp) movl - 48(%ebp), %eax subl $1, %eax movl %eax, -16(%ebp) jmp.L2 .L5: movl $0, -24(%ebp) jmp.L3 .L4: mrmovl - 24(%ebp), %eax irmovl $1, %ebx addl %ebx, %eax rrmovl %eax, %edx addl %edx, %edx addl %edx, %edx addl %edx, %edx mrmovl - 40(%ebp), %eax addl %edx, %eax mrmovl(%eax), %eax rmmovl %eax, -8(%ebp) mrmovl - 24(%ebp), %eax addl $1, %eax rrmovl %eax, %edx addl %edx, %edx addl %edx, %edx addl %edx, %edx mrmovl - 40(%ebp), %eax addl %eax, %edx mrmovl - 24(%ebp), %eax rrmovl %eax, %ecx addl %ecx, %ecx addl %ecx, %ecx addl %ecx, %ecx mrmovl - 40(%ebp), %eax addl %ecx, %eax mrmovl(%eax), %eax rmmovl %eax, (%edx) mrmovl - 24(%ebp), %eax rrmovl %eax, %edx addl %edx, %edx addl %edx, %edx addl %edx, %edx mrmovl - 40(%ebp), %eax addl %eax, %edx mrmovl - 8(%ebp), %eax rmmovl %eax, (%edx) pushl %edx mrmovl - 24(%ebp), %edx addl %ebx, %edx rmmovl %edx, -24(%ebp) popl %edx .L3: mrmovl - 24(%ebp), %eax mrmovl - 16(%ebp), %ebx xorl %eax, %ebx jne.L4 irmovl $1, %ebx pushl %edx mrmovl - 16(%ebp), %edx addl %ebx, %edx rmmovl %edx, -16(%ebp) popl %edx .L2 : mrmovl - 16(%ebp), %ebx andl %ebx, %ebx jg.L5 nop popl %ebx popl %ebp ret

4.56 int f_pc = [ # Mispredicted branch. Fetch at incremented PC

M_icode == IJXX && !M_Cnd : M_valA;//删除这一句用predPC代替

# Completion of RET instruction.
W_icode == IRET : W_valM;
# Default: Use predicted value of PC
1 : F_predPC;

]; int f_predPC = [ # BBTFNT: This is where you'll change the branch prediction rule f_icode in { ICALL } : f_valC; M_icode == IJXX &&M_ifun!=UNCOND&&!M_Cnd&&M_valE<M_valA:M_valA; M_icode == IJXX &&M_ifun!=UNCOND&&M_Cnd&&M_valE>=M_valA:M_valE; //判断如果前面有IJXX跳错了就变目标地址 f_icode ==IJXX&&f_ifun!=0&&f_valC<f_valP:f_valC; 1 : f_valP; ];

int aluA = [ E_icode in { IRRMOVL, IOPL } : E_valA; E_icode in { IIRMOVL, IRMMOVL, IMRMOVL ,IJXX} : E_valC;//加入IJXX E_icode in { ICALL, IPUSHL } : -4; E_icode in { IRET, IPOPL } : 4; # Other instructions don't need ALU ];

Select input B to ALU

int aluB = [ E_icode in { IRMMOVL, IMRMOVL, IOPL, ICALL, IPUSHL, IRET, IPOPL } : E_valB; E_icode in { IRRMOVL, IIRMOVL ,IJXX} : 0; //加入IJXX # Other instructions don't need ALU ]; //将E_valC传给M_valE

bool D_bubble = # Mispredicted branch (E_icode == IJXX && !e_Cnd&&E_valC<E_valA) ||(E_icode == IJXX && e_Cnd&&E_valC>=E_valA) || # BBTFNT: This condition will change # Stalling at fetch while ret passes through pipeline # but not condition for a load/use hazard !(E_icode in { IMRMOVL, IPOPL } && E_dstM in { d_srcA, d_srcB }) && IRET in { D_icode, E_icode, M_icode };

Should I stall or inject a bubble into Pipeline Register E?

At most one of these can be true.

bool E_stall = 0; bool E_bubble = # Mispredicted branch (E_icode == IJXX && !e_Cnd&&E_valC<E_valA) ||(E_icode == IJXX && e_Cnd&&E_valC>=E_valA) || # BBTFNT: This condition will change # Conditions for a load/use hazard E_icode in { IMRMOVL, IPOPL } && E_dstM in { d_srcA, d_srcB}; //改变对于跳转错误的判断,从而使遇到体题中这种跳转错误就bubble已入流水线的元素

5.13和5.14手写私发了

第五次作业反馈

第一题:Y86有点小问题
第二题:有误
第三题:有误
第四题:代码呢??

第四次作业 3.68 A:9 B:5

3.69 A:7 B: typedef struct { long idx; long x[4]; }a_struct

3.70 A: e1.p 0 e1.y 8 e2.x 0 e2.next 8 B:16 C:up->e2.x=*(up->e2.next->e1.p)-up->e2.next->e1.y

第四次作业反馈

第一题:正确
第二题:正确
第三题:正确

这是我的作业 3.60 A: x:%rdi,%r8 n:%esi,%ecx result:%eax mask:%edx B: result:0 mask:1 C: mask!=0 D: mask<<=(0xff&n) E: result|=(x&mask) F: 0 1 !=0 mask<<=(0xff&n) x&mask

3.62 A: result = *p2; action = *p1;//action是传的参变量,在此处改变他的值合适吗?还是只当做机器要用个寄存器? *p2 = action; break; B: result=*p1+*p2; *p1=result; break; C: *p1=59; result=*p2; break; D: result=*p2; *p1=result; result=27; break; E: result=27; break; default: result=12; break;

3.64
A: A+8*(TSi+T*j+k) B: R=7 S=5 T=13

第三次作业反馈

第一题:正确(严格来说,题目中的空在=后面,是不能写成<<=的)
第二题:有点小问题
第三题:正确

这是我的作业

2.61 ((!((unsigned char)(&x) - 255)) ||(!((((unsigned char)(&x + 1) - 1)) - 0)))

2.62 bool int_shifts_are_arithmetic() { return (bool)(-1 >> 70); }

2.65 int int_odd_ones(unsigned x) { int result = 0; short first = 0; short first_1 = 0; short first_2 = 0; char second = 0; char second_1 = 0; char second_2 = 0; char second_t = 0; bitset<4> third; bitset<4> third_1; bitset<4> third_2; bitset<4> third_t; bitset<2> fourth; bitset<2> fourth_1; bitset<2> fourth_2; bitset<2> fourth_t; bitset<1> fifth; first_1 = *((short *)(&x)); first_2 = *((short *)(&x) + 1); first = first_1^first_2; second_1 = *((char *)(&first)); second_2 = *((char *)(&first) + 1); second = second_1^second_2; second_t =( second << 4); third_1 = *((bitset<4> *)(&second)); third_2 = *((bitset<4> *)(&second_t)); third = third_1^third_2; fourth_1[0] = third[0]; fourth_1[1] = third[1]; fourth_2[0] = third[2]; fourth_2[1] = third[3]; fourth = fourth_1^fourth_2; fifth = (fourth[0]^fourth[1]); result = (int)&fifth; return (bool)result; }

第一次作业反馈

第一题:C、D对,A、B??
第二题:有误
第三题:有误

2.88 格式A: (208) (-14/2048==-7/1024) (5/131072) (-4096) (768) 格式B: [0 1110 1010](208) [1 0000 1110](-14/2048==-7/1024) [0 0000 0000](0) [1 1111 0000](-inf) [0 1111 0000](inf)

2.92 float float_negate(float f) { float y; int x; x = *(int *)(&f); int z; z = x&(~(1 << 31)); if (z > (0xff << 23)) { return f; } else { int a = x ^ (1 << 31); y = *(float *)(&a); return y; } }

2.96
int float_f2i(float f) { float y; int x; x = *(int *)(&f); int z; z = (x&((1 << 31))) >> 23; z = z - 127; if (z < 0) { return 0; } if (z > 30) { return 0x80000000; } int t=(((1 << 31)) >> 8); x = x&t; x <<= 8; x >>= (31 - z); x |= (1<<z); if (f < 0) { x = (~x) + 1; } return x; }

第二次作业反馈

第一题:有1个错误
第二题:逻辑上没错,但是题目中的float_bits意思其实是unsigned,并不是float,所以f<0恒不成立。还有,尽量别用指针
第三题:同上,所以f<0恒不成立