csci 10 :: midterm 3 (due wed, dec 3, AT START OF CLASS)

Fill in all of the "Answer" boxes, then print the answer grid that you see after you press "Prepare for printing".

Staple all pages together and submit to the instructor on the date listed above.

YOU MUST HAVE YOUR MIDTERM PRINTED WHEN YOU ARRIVE IN CLASS. YOU WILL NOT BE ALLOWED TO PRINT YOUR MIDTERM IN CLASS ON THE DAY IT IS DUE.

Questions:

This midterm covers all of the concepts you encountered on Book Learning Challenges 8, 9, 10, 11 and Programing Challenges 10, 11, 12, 13.

1. Write the following int8 value in binary.
10
2. Write the following int8 value in binary.
-10
3. Write all of the instructions needed to reverse the sign of the following int16 value. Be sure to include the instruction to store the new value back into the original variable.
static number: int16 := -100;
4. Write all of the instructions needed to reverse the sign of the following int16 value. Be sure to include the instruction to store the new value back into the original variable.
static number: int16 := 100;
5. What is the value of AL, in binary, after the following instructions execute? Is the carry bit set, or not set, by this operation?
mov(%0000_1010, AL);
6. What is the value of AL, in binary, after the following instructions execute? Is the carry bit set, or not set, by this operation?
mov(%1111_0110, AL);
7. Write the instruction to display AL, interpreted as a signed integer. If you were displaying the value produced by the instructions in the question #6 above, what would the output of be?
8. Write the instruction to display AL, interpreted as an unsigned integer. If you were displaying the value produced by the instructions in question #6 above, what would the output of be?
9. Write the code to load the address of the variable number into EBX.
static number: int16 := 9999;
10. Write the code to display the value of the variable number declared in question #9 above, using EBX (which already contains the address of number) and register-indirect addressing.
11. Write the code to load the value -9999 into the variable number declared in question #9 above, using EBX (which already contains the address of number) and register-indirect addressing.
12. What addressing mode is being used in the following code?
stdout.put(number, nl);
13. Write the code to display all of the values in the following array, one value per line, using indexed addressing with the array name. Do not use any high-level constructs, with the exception of stdout.put.
static counters: uns8[5] := [5, 10, 15, 20, 25];
14. Write the instruction to dynamically allocate and zero out an array of ten (10) int32 variables. Then, write the instruction to store the address in the variable baseAddress that is declared below.
15. Write the code to load baseAddress (declared in the question above) into register EBX, load the proper index value into ECX, and load the value 99999 into the first position (index 0) of the dynamic array that you allocated in question #14 above. Use scaled-indexed addressing.
16. Write the code to load baseAddress (declared in the question above)into register EBX, load the proper index value into ECX, and load the value -99999 into the last position (index 9) of the dynamic array that you allocated in question #14 above. Use scaled-indexed addressing.
17. Write the code to load the baseAddress into register EBX and display all of the values in the dynamic array that you allocated in question #14 above. Use scaled-indexed addressing. Do not use any high-level constructs, with the exception of stdout.put.
18. Write the code to free the memory associated with the dynamic array that you allocated in question #14 above.
19. Write the instruction to dynamically allocate and zero out an array of ten (10) int8 variables. Then, write the instruction to store the address in the variable baseAddress that is declared below.
20. Write the code to load the baseAddress into register EBX, load the proper index value into ECX, and load the value 99 into the first position (index 0) of the dynamic array that you allocated in question #19 above.
21. Write the code to load the baseAddress into register EBX, load the proper index value into ECX, and load the value -99 into the last position (index 9) of the dynamic array that you allocated in question #19 above.
22. Write the code to load the baseAddress into register EBX and display all of the values in the dynamic array that you allocated in question #19 above. Do not use any high-level constructs, with the exception of stdout.put.
23. Write the code to free the memory associated with the dynamic array that you allocated in question #19 above.
24. Translate the high-level decision in the following code into low-level HLA code.
if (choice == 1) then
stdout.put("apples");
elseif (choice == 2) then
stdout.put("bananas");
elseif (choice == 3) then
stdout.put("oranges");
else
stdout.put("unknown");
endif;