Csapp (deep understanding of computer Systems) Second Edition homework answer-chapter III __ Computer

Source: Internet
Author: User
The answer is by oneself completes, and experiment or debugging, welcome the reference.

3.54 int decode2 (int x,int y,int z) {int t=z-y;
	int t2=t<<15;
	t2=t2>>15;
Return (x^t) *t2; 3.55 MOVL (%EBP),%esi; The low movl of Get X (%EBP),%eax; Get y movl%eax,%edx sarl $31,%edx; the sign bit movl%edx,%ecx the imull;%esi,%ecx (0 or-1)%ecx=x (*y), MOVL; High Imull%eax,%ebx of Get x%ebx=x high *y addl%ebx,%ecx high%ecx=x low *y+x sign bit (0 or-1) *y Mull,%esi (x low%edx=) high *y x= (x's low *y) low Leal (%ecx,%edx),%edx MOVL 8 (%EBP),%ecx movl%eax, (%ECX) movl%edx,4 (%ECX) (x's low *y) high +x's low *y+x sign bit ( 0 or-1 low position stored at high (x low *y) in Low (Xl*y) _h+xh*y+xl*-1 (x1*y) _l xl=1000 xh=0000 y=1001 (x*yi=x*) yu-16 equivalent high = (=x*yu-16x) _ H-x, low = (X*yu) _l because this is mull unsigned multiplication 3.56 a. X:%esi,n:%ebx,result:%edi,mask:%edx B. result=0x55555555;
0101 0101 0101 0101 0101 0101 0101 0101;
	C. mask!=0 D. Mask Each loop to the right N-bit E. Result Each loop and x&mask the value of a different or F. int loop (int x,int n) {int result=0x55555555;
	int mask; for (mask=0x80000000;mask!=0 (unsigned) mask) >>n)//assembly mask is the logical right SHIFT, and mask is thereThe symbolic integral type should be converted to unsigned integral type to ensure that the right shift operator of the C language is compiled into the logic of the assembly to move right {result^=x&mask;
return result;
	3.57 int Cread_alt (int *xp) {int t=0;
	int *p=xp?xp:&t;
return *p;
	3.58 int Switch3 (int *p1,int *p2,mode_t action) {int result=0;
			Switch (action) {case MODE_A:RESULT=*P1;
			*P1=*P2;
		Break
			Case MODE_B:RESULT=*P1+*P2;
			*p2=result;
		Break
			Case Mode_c: *p2=15;
			RESULT=*P1;
		Break
		Case Mode_d: *P2=*P1;
			Case mode_e:result=17;
		Break
			Default:result=-1;
	Break
return result;
	3.59 int switch_prob (int x,int n) {int result=x;
			Switch (n) {case 40:case 42:result<<=3;
		Break
			Case 43:result>>=3;
		Break
			Case 44:result<<=3;
		Result-=x;
		Case 45:result*=result;
			Case 41://Can not default:result+=11;
	Break
return result;
} 3.60 A. A[i][j][k]=a+ ((2^6-1) *i+9j+k) *4=a+ (63i+9j+k) *4 B. t=9 s*t=63 r*s*t=2772/4=693 r=11 s=7 t=9 3.61 int var_prod_ele (int n, I NT A[n][n], int b[n][n], INT I, int k) {int result = 0;
    int *a = &A[i][0];
    int *b = &B[0][k];
    int *e = &A[i][n];
    for (; a!=e;)
        {result = *a * *B;
        B+=n;
    a++;
return result;
The following is the looping part of its assembly code: EDI is 4*N,EBX and edx respectively is B and A,esi is E,eax is result.
ECX is a register that is used to store multiplication. L4:MOVL (%EBX),%ecx imull (%edx),%ecx addl%ecx,%eax addl%edi,%ebx addl $,%edx cmpl%edx,%esi jne L4, Result,arow, Bcol,4*n these four values of memory required to convert the value of N to E to consume a register to compare the value of N and a, save the variable J, use a register less 3.62 a. m=76/4=19 B. i:%edi,j:ecx C. void Transpose (int A M
		[M]) {for (int i=0;i<m;i++) {int *arr=&a[i][0];
		int *brr=&a[0][i];
			for (int j=0;j<i;j++) {int t=*arr;
			*ARR=*BRR;
			*brr=t;
			Arr+=1;
		Brr+=m; }} 3.63 #define E1 (n) 3*n #define E2 (n) 2*n-1 3.64 A. 8 (%EBP) &s2 (%EBP) s1.p (%EBP) s1.v B.------------%eb P s2.sum s2.prod s1.v s1.p &s2------------%esp C. Passes the values of each member of the struct to method D. The caller passes the address of the return value variable to the method 3.65 a=3 b=7 3.66 the A.CNT=196/28
	=7 B. typedef struct {int idx; int x[6];
}a_struct; ap->idx=* (bp+1c*i+4) *4 ap->x[ap->idx]= (bp+4+28*i+4) +* (bp+0x1c*i+4) *4=bp+8+28i+* (bp+28i+4) *4=bp+8+4 (7i+ * (bp+28i+4)) 3.67 A. e1.p:0 e1.x:4 e2.y:0 e2.next:4 b.8 C. VOID proc (Union ele *up) {up->e2.next->e1.x=* (up->e
2.NEXT-&GT;E1.P)-up->e2.y;
    } 3.68 void Good_echo () {char C;
    int x = 0;
    while (X=getchar (), x!= ' \ n ' && x!=eof) {putchar (x);
	} 3.69 A. Long Trace (tree_ptr tp) {long result=0;
		while (TP) {result=tp->val;
	tp=tp->left;
return result; B. Output the value of the leftmost node of the binary tree 3.70 A. Long traverse (tree_ptr tp) {if (!TP) return 9223372036854775807;//long.max long V=tp->val
	;
	Long Left=traverse (tp->left);
	Long Result=traverse (tp->right);
	if (Left<result) result=left;
	if (result>v) result=v;
return result; B. Find the smallest value in a binary tree node


Original address: http://blog.csdn.net/maidou0921/article/details/53907971

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.