Name ______________________________________ Section ___________Some problems in this exam may rest on the subroutines NEW and DISPOSE. These may be called as follows:
a) as ASCII text shown in hexadecimal _____________ b) as a BCD number shown in binary _____________ c) as a binary number _____________ d) as an 8-bit two's complement binary number shown in hexadecimal _____________ e) as an 8-bit unsigned fixed point binary number with 2 places after the point, shown in hexadecimal _____________ f) as a 16-bit floating point number with a 10-bit signed-magnitude normalized binary mantissa and a 5 bit biased exponent, shown in hexadecimal _____________
function add(a,b -- both 32-bit integers) returns a + bWrite M68000 code for the function ADD using each of the following calling sequences:
Part A: A and B are passed in D0 and D1, the result is returned in D0. Any other registers that must be modified are restored prior to return (2 points).
_____________________________________________________ _____________________________________________________ _____________________________________________________Part B: The stack is used for all parameter passing. The calling program pushes first A then B then the return address. The result is returned on the stack top, with all other remains of the function removed from the stack. The function saves and restores any registers it needs to modify (2 points).
_____________________________________________________ _____________________________________________________ _____________________________________________________ _____________________________________________________ _____________________________________________________ _____________________________________________________ _____________________________________________________ _____________________________________________________ _____________________________________________________ _____________________________________________________Part C: ADD expects a pointer to its activation record to be passed in A0. The caller must allocate this activation record and initialize the fields ADDA and ADDB prior to the call. The result is returned in field ADDRES on exit, and the activation record includes a field ADDRET that must hold the return address during the execution of the body of ADD. Use of SP is avoided where not absolutely required by the above. The caller is responsible for deallocating the activation record. The called function must save and restore any registers it modifies; ADDSV is a field of the activation record sufficiently large to hold any registers the function must save (2 points).
_____________________________________________________ _____________________________________________________ _____________________________________________________ _____________________________________________________ _____________________________________________________ _____________________________________________________ _____________________________________________________ _____________________________________________________Write M68000 code to call the function ADD using each of the above calling sequences with the actual parameters taken from the variables A and B, and the result stored in the variable C. All of these variables are statically allocated!
Part D: A and B are passed in D0 and D1, the result is returned in D0. Any other registers that must be modified are restored prior to return (2 points).
_____________________________________________________ _____________________________________________________ _____________________________________________________ _____________________________________________________ _____________________________________________________Part E: The stack is used for all parameter passing. The calling program pushes first A then B then the return address. The result is returned on the stack top, with all other remains of the function removed from the stack. The function saves and restores any registers it needs to modify (2 points).
_____________________________________________________ _____________________________________________________ _____________________________________________________ _____________________________________________________ _____________________________________________________Part F: ADD expects a pointer to its activation record to be passed in A0. The caller must allocate this activation record and initialize the fields ADDA and ADDB prior to the call. The result is returned in field ADDRES on exit, and the activation record includes a field ADDRET that must hold the return address during the execution of the body of ADD. Use of SP is avoided where not absolutely required by the above. The caller is responsible for deallocating the activation record. The called function must save and restore any registers it modifies; ADDSV is a field of the activation record sufficiently large to hold any registers the function must save. Assume that ADDSZ is the size of the activation record for add (3 points).
_____________________________________________________ _____________________________________________________ _____________________________________________________ _____________________________________________________ _____________________________________________________ _____________________________________________________ _____________________________________________________ _____________________________________________________ _____________________________________________________
_____________________________________________________ _____________________________________________________ _____________________________________________________ _____________________________________________________ _____________________________________________________ _____________________________________________________ _____________________________________________________ _____________________________________________________
function count(t) if t=nil return 1 immediately otherwise, return count(t^.left) + count( t^.right) _____________________________________________________ _____________________________________________________ _____________________________________________________ _____________________________________________________ _____________________________________________________ _____________________________________________________ _____________________________________________________ _____________________________________________________ _____________________________________________________ _____________________________________________________ _____________________________________________________ _____________________________________________________ _____________________________________________________ _____________________________________________________ _____________________________________________________ _____________________________________________________ _____________________________________________________