Reflection on Week 4

Here is a basic Markdown template you can use for this week (and most of the quarter).

Part I: Reflection — Things I learned this week from the readings, videos, assignments, and/or in-class activities

(Don't just list things. Reflect. For example, you might think about the following questions, or others that occur to you: Etc. From week to week, different questions might strike you as useful prompts to help you reflect on your learning experience.)

Part II: Specific Questions for this Week

  1. The array indexing syntax you are used to from C or Java is just "syntactic sugar" for some pointer arithmetic:
    A[i] is equivalent to *(A+i)
    where (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!?)
  2. 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?

  3. 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;
                }