Here is a basic Markdown template you can use for this week (and most of the quarter).
whereA[i]
is equivalent to*(A+i)
(A + i)
really means
A + (i * sizeof(itemtype))
(because pointer
arithmetic). Does knowing this help you understand the MIPS code
required to access an array element, or does understanding the MIPS
code help you to understand the C pointer arithmetic version? (Or
neither!?)
Reflecting on the recursive and non-recursive assembly language implementations you wrote for the Triangular Number function, what does that tell you about the overhead involved in function calls?
Optional: If you also implemented the optional tail-recursive algorithm, why did the tail-recursive version require fewer Stack push and pop operations than the non-tail-recursive version?
Use what you learned implementing the two Triangular Number functions to explain why the code on the left is more efficient than the code on the right.
int i; int dec = 0, powOf2 = 1; for ( i = end; i >= begin; i-- ) { if ( input[i] == '1' ) dec += powOf2; powOf2 *= 2; } |
int i; int dec = 0, exp = 0; for ( i = end; i >= begin; i-- ) { if ( input[i] == '1' ) dec += pow(2, exp); exp++; } |
Optional: If you want, describe why the code below is even more efficient than the code on the left above.
int * ptr; int * beginAddr = &input[begin]; int dec = 0, powOf2 = 1; for ( ptr = &input[end]; ptr >= beginAddr; ptr-- ) { if ( *ptr == '1' ) dec += powOf2; powOf2 = powOf2 << 1; }