CS 354 Midterm 1a, 33.33% Monday, October 9th, 2000 Solution Parts Number of Questions Question Format Possible Points Score I 6 Short Answer 20 II 5 Multiple Choice 15 III 5 True or False 10 IV 6 Calculations 30 V 3 Coding 25 Total 100 2000Deb Deppeler page: 1 Page Score: SOLUTION
Part I Short Answer [6 questions for a total of 20 total points] For questions 1 through 6, write your answers clearly and concisely. 1.) (3 points) What is an assembler directive? Assembler directives are instructions to the assembler rather than insturctions to be executed as part of the program. 2.) (2 points) Give an example of an assembler directive that can be used in a SAL program. Examples include.data,.byte,.word,.float,.space,.text 3.) (6 points) List (or briefly explain) each step in the execution of an arithmetic instruction. 1. Fetch the instruction from memory. 2. Update the program counter (PC) to point to the next instruction. 3. Decode the instruction that was retrieved in step 1. 4. Load source operands (this may require 0-2 memory accesses) 5. Execute the instruction 6. Store the results of the execution. 4.) (2 points) Explain how the steps in question 3 would be different if the instruction being executed was a branch instruction instead of an arithmetic instruction. There would be no store of the results, but instead step 6 would modify the program counter if the branch condition was true. 5.) (2 points) Explain how the steps in question 3 would be different if the instruction being executed was a logical or a shift instruction instead of an arithmetic instruction. The steps would be the same as for arithmetic instructions. 6.) (5 points) Describe how the SAL assembly programming language is an abstraction of the underlying machine language of a machine. (Hint: Briefly describe what an abstraction is and how SAL fits that definition.) An abstraction is a simplified model of something that hides unimportant details from view. One way that SAL is an abstraction of a true assembly language and the underlying machine language the fact that it allows the programmer to access memory through labels (like variables) instead of having to use the address of a memory location. 2000Deb Deppeler page: 2 Page Score: SOLUTION
Part II Multiple Choice [5 questions, 3 points each, 15 total points] For questions 1 through 5, choose the one best answer after reading ALL of the choices. Circle the corresponding letter on this page. 1.) Which of the following SAL instructions has the same effect as the Java statement? count++; A. move count, count, 1 B. sub count, count, -1 C. add count, count, 1 D. All of the above E. B and C above 2.) How many distinct values can be represented in 17 bits? A. 2 (17-1) + 1 B. 2 (17-1) C. 2 17 D. 2 17-1 E. 2 (17-1) - 1 3.) What does the following hexidecimal value represent? 0xA3409BC2 A. an unsigned binary integer B. a negative IEEE floating point real C. four characters D. a negative twos complement integer E. can t be determined from information given 4.) Which of the following statements is not true? A. If the head pointer equals the tail pointer of a circular queue, the queue may be empty or full. B. Stacks and queues are implemented in SAL by reserving a contiguous block of memory and using other memory cells to keep track of the contents of that block of memory cells. C. Data can be stored in SAL arrays in either row-major order or column-major order. D. A two- dimensional array of characters can be declared using the syntax: ch:.byte 0 :3:4 E. Data structures are used to organize memory to make data retrieval more efficient. 5.) The range of valid decimal integers that can be represented in 32-bit two s complement is: A. -2,147,483,648 to 2,147,483,648 B. -2,147,483,648 to 2,147,483,647 C. -2,147,483,647 to 2,147,483,648 D. -2,147,483,647 to 2,147,483,647 E. -2,147,483,646 to 2,147,483,647 2000Deb Deppeler page: 3 Page Score: SOLUTION
Part III True or False [5 questions, 2 points each, 10 total points] Circle true or false for each statement. If both are marked your answer will be marked inccorrect. 1.) ( true / false) The MIPS architecture uses two s complement representation to store integer values. 2.) (true / false) Procedures written in SAL can not have parameters. 3.) ( true / false) Read data from and write data to are the only operations that can be performed on memory. 4.) ( true / false) The load address instruction (in SAL) is used to store the return address in an integer variable before making the call to a procedure. 5.) (true / false) High level languages are usually translated directly into machine language by an assembler. FALSE, HLLs are almost always compiled first into assembly language before being assembled into machine language. 2000Deb Deppeler page: 4 Page Score: SOLUTION
Part IV Calculations [6 questions for a total of 30 points] Show all work for these questions. Full credit will not be given without work. Write in English what you would do, if you are unable to complete the actual calculation. If you need more room, use the back of the page and indicate your work continues on the back. Additional work pages may be requested from your exam proctor. You must turn in any additional work pages with your exam. 1.) (6 points) Complete the following table. The column heading tells which number system to use to represent the value for each row. See reference pages for a table of Roman Numerals. decimal unsigned binary base 7 Roman Numerals 55 110 106 LV 118 0110 226 CXVIII 2.) (5 points) Given a 10 x 17 array of words (10 rows x 17 columns) with a base address of 0x00400000, what is the address of the third word in the second row? You should assume byte-addressability and columnmajor order. Show your work for full credit. Use hexidecimal notation to show the final address of the specified word. 0x0040000 + (2-0)(10 rows)(4 bytes) + (1-0)(4 bytes) = 0x00400000 + 8(10) + 4 = 0x00400000 + 01010100 2 = 0x00400000 + 0x54 = 0x00400054 3.) (3 points) What is the 8-bit result of adding the following sign-magnitude numbers? Write OVERFLOW if the result can not be represented in 8-bit sign-magnitude. 10001101 => 1 0001101 1 1001 + 01001-1 1001-1 0001101 ---------- ----------- ----------- 0 1000 change sign to positive after changing order of subtraction 4.) (6 points) What is the decimal equivalent of the following hexidecimal value if it is interpreted as an IEEE 32-bit single precision value? 0x43A6E800 1. Convert to binary 0100 0011 1010 0110 0 1000 0000 0000 2. Separate into SEF S=0 E=1000 0 F=010 0110 0 1000 0000 0000 3. Sign is positive. 4. Exponent e = E - 127 = 135-127 = 8 5. Mantissa = 1.F = 1.010 0110 0 1000 0000 0000 6. Binary value = +1.010 0110 0 1000 X 2 8 7. Un-normalized = 101001101.1101000 X 2 8 8. Decimal value = 256+64+8+4+1 +.5 +.25 +.0625 = 333.8125 2000Deb Deppeler page: 5 Page Score: SOLUTION
5.) (5 points) Perform the following division of two unsigned binary values. 11010011 / 00000 = 00010.001001 (repeats 001 from here) ------------------------- / 11010011.0000000000 ---- 1100 I ---- 1010 ---- --- 01 000 --- 1000 (repeats above) 6.) (5 points) Show the two s complement multiplication of the following two integers. Convert your answer to decimal. 00010101 x 11010 ----------- 1 1 1 1010 * 0000 0000 0001 0101 --------------------- 1 1 1 1 1 1010 1010 1011 (carry bit) 1 1 1 1010 11 1 1 0 1000 + 1 1 1 1010 0000 -------------------------- 1 1 1000 0010 (ignore carry-out of msb) The decimal value is = -124 2000Deb Deppeler page: 6 Page Score: SOLUTION
Part V Coding [3 questions, 25 total points] 1.) Answer the questions that follow this SAL program by examining the code and tracing the execution of this program..data aa:.word 0:32 bb:.word cc:.word dd: ee:.byte.word.text start: la bb, aa la ee, ff b hh ff: la bb, aa add cc, bb, 84 move dd, m[cc] put dd add cc, cc, -2 move dd, m[cc] put dd add move put put cc, bb, 0x45 dd, m[cc] dd dd add cc, bb, 33 move dd, m[cc] put dd put \n gg: done hh: add bb, bb, 32 move dd, ii: move m[bb], dd add dd, dd, 1 add bb, bb, 1 ble dd, 90, ii b (ee) A. (2 points) There is one procedure implemented in this program. What is the label at the start of that procedure? hh B. (5 points) What does that procedure do? It initializes part of the array aa to the ASCII characters from the space character ( ) to the capital letter ( Z ) C. (5 points) What does the program print? TREE! 2000Deb Deppeler page: 7 Page Score: SOLUTION
2.) (8 points) Fill in the following procedure that prints a number in any base between 2 and 10. Assume that the caller has correctly initialized the variable int with a positive decimal value to be represented and the variable base with a valid radix to be used to display the value..data print_integer_ra:.word # the return address has been initialized int:.word # the integer has been initialized base:.word # the base has been initialized result:.byte :50 start:.word result sp:.word result ch:.byte digit:.word quot:.word size:.word.text print_integer: move quot, int next: rem digit, quot, base div quot, quot, base sub ch, digit, 0 move m[sp], ch add sp, sp, size bnez quot,next pnext: sub put bgt b sp, sp, size m[sp] sp, start, pnext (print_integer_ra) 3.) (5 points) What is the binary representation of the contents of variable x after the following code fragment has been executed? (Show the value after each instruction for partial credit).data x:.word.text start: move x, -15 # 1 1 1 1 1 1 1 0001 sll x, x, 4 # 1 1 1 1 1 1 0001 0000 srl x, x, 4 # 0000 1 1 1 1 1 1 0001 ror x, x, 2 # 0100 0011 1 1 1 1 1 1100 # 0 1000 0011 0010 0001 0000 0 1 xor x, x, 0xe83210ef # 1010 1011 1100 1101 0 1 0001 0011 2000Deb Deppeler page: 8 Page Score: SOLUTION