csci 10 :: midterm 3 (due wed, dec 3, AT START OF CLASS)
Submitting your work: Complete this exercise on your own.

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.

Your name:
  1. Write the following int8 value in binary.
    10
    Answer:
  2. Write the following int8 value in binary.
    -10
    Answer:
  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;
    Answer:
  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;
    Answer:
  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);
    add(%1111_0111, AL);
    Answer:
  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);
    add(%0000_1001, AL);
    Answer:
  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?
    Answer:
  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?
    Answer:
  9. Write the code to load the address of the variable number into EBX.
    static number: int16 := 9999;
    Answer:
  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.
    Answer:
  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.
    Answer:
  12. What addressing mode is being used in the following code?
    stdout.put(number, nl);
    Answer:
  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];
    Answer:
  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.
    static baseAddress: dword;
    Answer:
  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.
    Answer:
  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.
    Answer:
  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.
    Answer:
  18. Write the code to free the memory associated with the dynamic array that you allocated in question #14 above.
    Answer:
  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.
    static baseAddress: dword;
    Answer:
  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.
    Answer:
  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.
    Answer:
  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.
    Answer:
  23. Write the code to free the memory associated with the dynamic array that you allocated in question #19 above.
    Answer:
  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;
    Answer:
  25. Write a complete procedure printArray that has parameters baseAddress (dword), arraySize (uns32), and dataType (uns8). baseAddress will contain the address of a dynamic array, arraySize will contain the total number of items in the array, and dataType will contain either 1 (int8), 2 (int16), or 3 (int32). In the body of the procedure, write the code to print the contents of the dynamic array, scaled properly based on the value of the parameter dataType. Do not use any high-level constructs, with the exception of stdout.put.
    Answer:

Total points for this book learning challenge:

500 points