231 Fall 2007 -- Final Exam Name: _______________________ No calculators. Matching. Indicate the letter of the best description. (1.5 pts. each) 1. _____ address a. name of register b. name of memory location 2. _____ opcode c. specifies addressing mode d. specifies operation to perform 3. _____ object code e. binary machine code with unresolved external references 4. _____ condition code f. binary machine code that is ready to execute g. code resulting from conditional compilation 5. _____ static linking h. summary value reflecting outcome of last recorded ALU operation 6. _____ programmed I/O i. linking performed while building an object file j. linking performed while building an executable 7. _____ DMA I/O k. linking performed at run time l. single byte transferred using polling 8. _____ callee-save m. single byte transferred using interrupt n. single contiguous block transferred 9. _____ interpretation o. multiple non-contiguous blocks transferred p. register values are saved by the caller before 10. _____ compilation call, and later restored by caller after return q. register values are saved by the called subroutine at entry, and later restored by the subroutine just prior to return r. translation of high-level source code into machine instructions that can be executed at later time by the computer s. translation and immediate execution of code 11. Consider the following C code. int x = 1; int y; int main(void){ int *z; z = malloc(sizeof(int)); *z = x; y = *z; free( z ); return 0; } Among .bss, .data, heap, stack, and .text - where are the variables allocated? (1 pt. each) x is in ______________ y is in ______________ z (the pointer itself) is in ______________ *z (the object pointed to) is in ______________ 12. (a) Why do assemblers use two passes? __________________________________ (Hint: two words.) (2 pt.) (b) What does the first pass do? increment the ________________________ (Hint: two words each.) and (1 pt. each) build the ____________________________ (c) What does the second pass do? ______________________________________ (Hint: one word.) (1 pt.) 13. What is the most negative 10-bit two's complement number? Please give both the hexadecimal representation and the decimal representation. (4 pts.) 14. What is the most positive 10-bit two's complement number? Please give both the hexadecimal representation and the decimal representation. (4 pts.) 15. Convert these numbers between signed decimal and 16-bit two's complement representation. (3 pts. each) signed decimal two's complement (a) -10 ________ (b) ________ 0xfff0 (c) 100 ________ (d) ________ 0x0100 16. Show the little-endian and big-endian byte ordering of the following data values. Start the byte numbering of i and c[] at address 100. (4 pts.) int i = 0x12345; /* int defaults to a 32-bit word */ char c[4] = {'a', 'b', 'c', '\0'}; byte address: 100 101 102 103 104 105 106 107 big-endian ordering: ___ ___ ___ ___ ___ ___ ___ ___ little-endian ordering: ___ ___ ___ ___ ___ ___ ___ ___ 17. List the elements of an array "a[2][2]" in row-major storage order. (3 pts.) (First element is a[0][0].) 18. Consider the simple 5-bit floating-point format we used in class: one sign bit, two exponent bits with the exponent encoded in bias-2 notation, two fraction bits, and a hidden bit. Show the 5-bit values for these decimal numbers and mark on the number line: (3 pts. each) 2**(-1) 2**0 2**1 _____ ___________ ______________________ 0 / \ / \ / \ |-|-|-|-|-|-|-|-|---|---|---|---|-------|-------|-------| (a) +0.625 = __ (____) ____ (b) +1.25 = __ (____) ____ (c) -2.5 = __ (____) ____ Extra Credit 1: Show the steps required in the addition of the first two floating-point numbers you represented in question 18. (up to 5 pts.) 19. Consider the following C code int f0( int x ); /* function prototype */ int v = 4; /* global variable */ int main(){ int (* fp)(int) = f0; /* declare and initialize a function pointer */ ( * fp )( v ); /* make the call via the function pointer */ return 0; } int f0( int x ){ if( x == 0 ) return 0; else return f0( x - 1 ); } Consider three separately assembled modules A, B, and C for the program. Answer parts (a), (b), (c), and (d) on the right hand side. For (a), (b), and (d), circle "Yes" or "No" and fill in the blank if "Yes". (The generated code has been edited.) (2 pts. each) separately assembled module A: .section ".text" .global main,v,f0 main: save %sp,-96,%sp 0x00 (a) Can this value be set by sethi %hi(v),%g1 0x04 (______) the assembler? Yes or No or %g1,%lo(v),%g1 0x08 ( " ) (If yes, fill in value.) ld [%g1],%o0 0x0c sethi %hi(f0),%g1 0x10 (______) (b) Can this value be set by or %g1,%lo(f0),%g1 0x14 ( " ) the assembler? Yes or No call %g1 0x18 (If yes, fill in value.) nop 0x1c mov 0,%i0 0x20 ret 0x24 restore 0x28 separately assembled module B: .section ".data" (c) Why is v in .data rather .global v than .bss? v: .word 4 0x00 4 separately assembled module c: .section ".text" .global f0 f0: save %sp,-96,%sp 0x00 cmp %i0,0 0x04 be L1 0x08 mov 0,%o0 0x0c add %i0,-1,%o0 0x10 call f0 0x14 (_______) (d) Can this value be set by nop 0x18 the assembler? Yes or No L1: mov %o0,%i0 0x1c (If yes, give value.) ret 0x20 restore 0x24 20. Identify the five items in a generic stack frame (1.5 pts. each) (1) (2) (3) (4) (5) 21. Identify and briefly explain at least three components of an ABI specification. (2 pts. each) (1) (2) (3) 22. Why should a programmer care about an ABI? That is, why is an ABI a good thing to have? (2.5 pts.) 23. Name the four generic hardware actions that occur when the CPU accepts an interrupt signal. (2 pts. each) (1) (2) (3) (4) 24. Give typical speeds and sizes for the following. (1 pt. each) (a) CPU clock frequency of current microprocessor (e.g., Intel or AMD) (b) number of registers in a CPU (c) main memory size of current laptop or desktop (d) storage capacity of disk drive for current laptop or desktop 25. A disk requires 5 ms (milliseconds) on average to seek, 2.5 ms for average rotational delay, and 0.01 ms to transfer 512 bytes. What is the effective transfer rate for 512 bytes if you consider the time required for seek, rotational delay, and actual data transfer? (Set up the equation in terms of effective number of bytes per second. A numeric solution is not required.) (4 pts.) Extra Credit 2. Give the SPARC code for the following string function. (up to 10 pts.) /* string length routine * * input parameter: * %i0 - address of string (assumption: string ends in null byte) * * return value: * %i0 - string length * * local register usage: * %ptr_r - %l0 - string pointer, initialized to input value * %byte_r - %l1 - holds byte at current string pointer * %len_r - %l2 - current length */ define(`ptr_r', l0) define(`byte_r', l1) define(`len_r', l2) .global length length: