Name ______________________________________ Section ___________ E-mail address to which you want your grade sent ________________________________________This exam is open-book and open-notes, but closed neighbor! You have two hours. Answer the questions in the space provided. If you need scratch paper, feel free to use the backs of the exam pages, but please transcribe your answers into the blanks provided.
___________________________________________________________________ ___________________________________________________________________ ___________________________________________________________________ ___________________________________________________________________ ___________________________________________________________________
reverse(t) procedure reverse(t:noderef) struct node * t var temp:noderef; { begin struct node * temp if t <> nil then begin if (t != NULL) { reverse( t^.left ); reverse( t->left ); reverse( t^.right ); reverse( t->right ); temp := t^.left; temp = t->left; t^.left := t^.right; t->left = t->right; t^.right := temp; t->right = temp; end; } end; } _____________________________________________________ _____________________________________________________ _____________________________________________________ _____________________________________________________ _____________________________________________________ _____________________________________________________ _____________________________________________________ _____________________________________________________ _____________________________________________________ _____________________________________________________ _____________________________________________________ _____________________________________________________ _____________________________________________________ _____________________________________________________ _____________________________________________________ _____________________________________________________ _____________________________________________________ _____________________________________________________ _____________________________________________________ _____________________________________________________ _____________________________________________________ _____________________________________________________ _____________________________________________________
int A[5][9]; A: array [0..4,0..8] of integer;Write good Hawk code to fetch A[i,j] into R3, assuming that integers are 32 bits and, R4 and R5 initially hold i and j, and your code is free to wipe out both R4 and R5 (3 points).
_____________________________________________________ _____________________________________________________ _____________________________________________________ _____________________________________________________ _____________________________________________________ _____________________________________________________ _____________________________________________________ _____________________________________________________ _____________________________________________________ _____________________________________________________
_______________________________ _______________________________ |_______________________________|_______________________________| |31 dst 16|15 src 0|This instruction is a conditional move instruction, moving data from M[src] to M[dst] when the condition bit is zero; the instruction always clears the condition bit just before storing the operand. Instructions are executed in sequence, just as on a typical modern machine. This machine would be useless if it were not for the fact that all registers inside the machine are memory mapped!
_____________________________________________________ _____________________________________________________ _____________________________________________________ _____________________________________________________ _____________________________________________________ _____________________________________________________ _____________________________________________________ _____________________________________________________ _____________________________________________________ _____________________________________________________ _____________________________________________________ _____________________________________________________ _____________________________________________________ _____________________________________________________ _____________________________________________________ _____________________________________________________