首页 > > 详细

CIS 314 Assignment 6

 Winter ’19 CIS 314 Assignment 6 – 100/100 points – Due Monday, 3/11, 11:59 PM

Please submit individual source files for coding exercises (see naming conventions below) and a single solution document for non-coding exercises (.txt or .pdf only). Your code and answers need to be documented to the point that the graders can understand your thought process. Full credit will not be awarded if sufficient work is not shown.
1. [20] Consider the following C code:
int f(int a, int b, int c, int d, int n) {
int result = 0;
for (int i = 0; i < n; ++i) {
for (int j = 0; j < n; ++j) {
result += a * b + i * c * d + j;
}
}
return result;
}
Rewrite the above procedure f to minimize unnecessary multiplications.
Here are some test runs:
f(1, 2, 3, 4, 5): 700
f(2, 3, 4, 5, 6): 2106
f(6, 5, 4, 3, 2): 146
f(5, 4, 3, 2, 1): 20
Also write a main() function to test your procedure. Name your source file 6-1.c.
2. [50] Suppose we’ve got a procedure that computes the inner product of two arrays u and v. Consider the following C code:
void inner(float *u, float *v, int length, float *dest) {
int i;
float sum = 0.0f;
for (i = 0; i < length; ++i) {
sum += u[i] * v[i];
}
*dest = sum;
}
The x86-64 assembly code for the inner loop is as follows:
# u in %rbx, v in %rax, length in %rcx, i in %rdx, sum in %xmm1
.L87:
movss (%rbx, %rdx, 4), %xmm0 # Get u[i]
mulss (%rax, %rdx, 4), %xmm0 # Multiply by v[i]
联系我们
  • QQ:99515681
  • 邮箱:99515681@qq.com
  • 工作时间:8:00-21:00
  • 微信:codinghelp
热点标签

联系我们 - QQ: 99515681 微信:codinghelp
程序辅导网!