[关闭]
@Radon 2014-10-23T09:33:14.000000Z 字数 1306 阅读 1729

Homework 5 & 6

1100012749



3.61

  1. int var_prod_ele(int n, int A[n][n], int B[n][n], int i, int k) {
  2. void *Arow = (void *)&A[i][0];
  3. void *Bcol = (void *)&B[0][k];
  4. int j;
  5. int result = 0;
  6. int NN = 4*n;
  7. for (j = 0; j < NN; j+=4){
  8. result += *((int *)(Arow+j)) * *((int *)Bcol);
  9. Bcol += NN;
  10. }
  11. return result;
  12. }
$ gcc -O2 -S ics3.61.c -m32
  1. .L4:
  2. movl (%ebx), %ecx
  3. addl %esi, %ebx #esi->NN, ebx->Bcol
  4. imull (%edi,%edx), %ecx #ecx=(*Bcol) * *(Arow+j), edi->Arow
  5. addl $4, %edx #edx->j
  6. addl %ecx, %eax #eax->result
  7. cmpl %edx, %esi
  8. jg .L4

3.62

A. 13
B. i: %edi; j: %ecx
C.

  1. void transpose(int M, int A[M][M]){
  2. int i, j, *A1, t;
  3. for (i = 0; i < M; i++){
  4. A1 = &A[0][i];
  5. A_ = A[i];
  6. for (j = 0; j < i;){
  7. t = A_[j];
  8. A_[j] = *A1;
  9. j++;
  10. *A1 = t;
  11. A1 += M;
  12. }
  13. }
  14. }

3.64

A.
8(%ebp)存放返回值的地址
12(%ebp)存放s1.a
16(%ebp)存放s1.p
B.

%ebp->
s2.diff
s2.sum
s1.p
s1.a
%esp-> &s2

C.
将结构的每一个成员逆序压入栈中
D.
预先从低到高地址分配结构各个成员的空间,在栈中retaddr+4的位置提供一个指向结构的指针作为返回地址


3.67

A.

e1.p: 0
e1.y: 4
e2.x: 0
e2.next: 4

B. 8个
C. up->next->y = *(up->next->p) - up->x;

3.68

  1. #include <stdio.h>
  2. #define MAX_INPUT 10
  3. int good_echo()
  4. {
  5. char s[MAX_INPUT];
  6. char *ret;
  7. do{
  8. ret = fgets(s, MAX_INPUT, stdin);
  9. if(ret == NULL){
  10. if(feof(stdin)) return 0;
  11. else return 1;
  12. }
  13. fputs(s, stdout);
  14. } while(true);
  15. }
  16. int main()
  17. {
  18. return good_echo();
  19. }

3.70

  1. #define MIN_VAL -9223372036854775807-1
  2. long traverse(tree_ptr tp)
  3. {
  4. if (!tp)
  5. return MIN_VAL; //movabsq??
  6. long v = tp->val;
  7. long vLeft = traverse(tp->left);
  8. long vRight = traverse(tp->right);
  9. if (vLeft >= vRight) vRight = vLeft;
  10. if (vRight < v) vRight = v;
  11. return vRight;
  12. }
添加新批注
在作者公开此批注前,只有你和作者可见。
回复批注