Section 9.7: A pointer example (Frame 1)                     [     ][home][next]

Remember the discussion in Section 8.5 of how LDS and STS worked? Towards the end of that section, we saw how an array of integers can be added up using LDS. The following C program and the subsequent CSC-1 assembler program implement that program directly, using pointers rather than array indexes as in the last section.

main()
{
     int array[5];    /* contains 8, 2, 1, 4, 6 */
     int sum;
     int *pointr;
     int i;
     int max = 5;

     pointr = &array[0];
     sum = 0;
     i = 0;

     while (i < max) {       /* could have used a for loop here */
          sum += *pointr;
          pointr++;
          i++;
     }
}