That gets us the three lines of output:
A[0] : 1048972 A[1] : 1048948 A[2] : 1048940For the lines involving b, we need to look at what b[0], b[1] and b[2] point to:
That allows us to print the next three sets of lines:
B[0] : 0x100174 B[0][0] : 1048956 B[0][1] : 1048924 B[0][2] : 1048936 B[1] : 0x100140 B[1][0] : 1048948 B[1][1] : 1048940 B[1][2] : 1048936 B[2] : 0x100150 B[2][0] : 1048956 B[2][1] : 1048944 B[2][2] : 1048948The next loop is a little tricky. This is not a regular doubly-linked list. To figure it out, start with p equaling head, and treat the 12 bytes as a flink, blink and val as pictured below, lableled "first p." We chase those flink pointers to get each successive p:
That gives us the next three lines of output:
0: p: 0x100178 p->val: 1048884 1: p: 0x10015c p->val: 1048896 2: p: 0x100140 p->val: 1048936Then, starting with p = 0x100140, we chase blink pointers, which are the second four bytes of each p. I do this in two drawings, because the last p overlaps with the fifth p:
And that gives us the last three lines of output:
0: p: 0x10016c p->val: 1048956 1: p: 0x100178 p->val: 1048884 2: p: 0x100168 p->val: 1048952
#include <stdio.h> #include <stdlib.h> #include <string.h> #include "fields.h" main() { char *l, *p; IS is; l = NULL; p = NULL; is = new_inputstruct(NULL); while (get_line(is) >= 0) { if (p != NULL) free(p); p = l; l = strdup(is->text1); } if (p != NULL) printf("%s", p); exit(0); } |
There are of course other ways to do this.
Grading: 4 points per part.
Now, we're in b(8). It decrements the stack pointer 4 bytes to allocate j and sets j to three. Since the if statement is false, it recursively calls b on 8+5 = 13. That part of the stack is:
Now, we're in b(13). Again, it allocates j and sets it to three. Since i is indeed greater than 10, it now pushes &i and i onto the stack, and calls jsr a:
Finally, we're in a(). It allocates k, and calculates i + *jp. Since jp equals 0xfff474, *jp equals 13, so k is set to 26. 27 is put into r0, and we return with the entire stack looking as follows: