csci 10 :: midterm 2 (due mon, oct 28, 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 5, 6, and 7 and Programing Challenges 6, 7, 8, and 9.

Your name:
  1. Write all of the instructions needed to do the following:
    • translate the following high level expression into assembly code (do not declare variables -- assume x has been properly declared as an uns8 variable)
    • output the dividend in both hexadecimal and decimal formats, in a single statement, using only registers
    • output the remainder in both hexadecimal and decimal formats, in a single statement, using only registers

    x = x / 2;
    Answer:
  2. Write all of the instructions needed to do the following:
    • translate the following high level expression into assembly code (do not declare variables -- assume x has been properly declared as an int8 variable)
    • output the dividend in both hexadecimal and decimal formats, in a single statement, using only registers
    • output the remainder in both hexadecimal and decimal formats, in a single statement, using only registers

    x = x / 2;
    Answer:
  3. Write all of the instructions needed to do the following:
    • translate the following high level expression into assembly code (do not declare variables -- assume x has been properly declared as an uns16 variable)
    • output the dividend in both hexadecimal and decimal formats, in a single statement, using only registers
    • output the remainder in both hexadecimal and decimal formats, in a single statement, using only registers

    x = x / 10;
    Answer:
  4. Write all of the instructions needed to do the following:
    • translate the following high level expression into assembly code (do not declare variables -- assume x has been properly declared as an int16 variable)
    • output the dividend in both hexadecimal and decimal formats, in a single statement, using only registers
    • output the remainder in both hexadecimal and decimal formats, in a single statement, using only registers

    x = x / 10;
    Answer:
  5. Write all of the instructions needed to do the following:
    • translate the following high level expression into assembly code (do not declare variables -- assume x has been properly declared as an uns32 variable)
    • output the dividend in both hexadecimal and decimal formats, in a single statement, using only registers
    • output the remainder in both hexadecimal and decimal formats, in a single statement, using only registers

    x = x / 100;
    Answer:
  6. Write all of the instructions needed to do the following:
    • translate the following high level expression into assembly code (do not declare variables -- assume x has been properly declared as an int32 variable)
    • output the dividend in both hexadecimal and decimal formats, in a single statement, using only registers
    • output the remainder in both hexadecimal and decimal formats, in a single statement, using only registers

    x = x / 100;
    Answer:
  7. What is wrong with the following code, assuming it is written in a correct HLA program and that the variable number has been declared as a static uns32 variable?
    mov(1000, number);
    mov(number, eax);
    mov(0, edx);
    div(100, eax);
    Answer:
  8. What is wrong with the following code, assuming it is written in a correct HLA program and that the variable number has been declared as a static uns16 variable?
    mov(100, number);
    mov(number, ax);
    div(10, dx:ax);
    Answer:
  9. What is wrong with the following code, assuming it is written in a correct HLA program and that the variable number has been declared as a static int16 variable?
    mov(100, number);
    mov(number, ax);
    mov(0, dx);
    div(10, dx:ax);
    Answer:
  10. What is wrong with the following code, assuming it is written in a correct HLA program and that the variable number has been declared as a static int8 variable?
    mov(10, number);
    mov(number, al);
    cbw();
    div(2, al);
    Answer:
  11. What register does an x86 processor use to control its stack?
    Answer:
  12. What will be the value of ESP after the following instruction is executed?
    // GIVEN: ESP value starts at $00FF_FFEA
    push(eax);
    Answer:
  13. What will be the value of ESP after the following instruction is executed?
    // GIVEN: ESP value starts at $00FF_FFEF
    pop(eax);
    Answer:
  14. According to your text, should you usually use (1) 16-bit or (2) 32-bit push/pop operations to achieve maximum performance, in a 32-bit environment?
    Answer:
  15. Write the assembly instructions needed to preserve the values in the registers AX and DX around the following code (write your instructions to achieve maximum performance).
    mov(10, ax);
    mov(0, dx);
    div(3, dx:ax);
    Answer:
  16. Write the assembly instructions needed to preserve the value in the register CL around the following code (write your instructions to achieve maximum performance).
    for (mov(0, cl); cl<10; inc(cl)) do
         stdout.put("*");
    endfor;

    Answer:
  17. What is the value of AL after the following instructions? Write your answer in binary, preceding the binary value with % and separating each nibble with an underscore.
    mov(%1111_0000, al);
    not(al);
    Answer:
  18. What is the value of AL after the following instructions? Write your answer in binary, preceding the binary value with % and separating each nibble with an underscore.
    mov(%1001_1001, al);
    and(%0000_0001, al);
    Answer:
  19. What is the value of AL after the following instructions? Write your answer in binary, preceding the binary value with % and separating each nibble with an underscore.
    mov(%1111_0000, al);
    and(%0000_1111, al);
    Answer:
  20. What is the value of AL after the following instructions? Write your answer in binary, preceding the binary value with % and separating each nibble with an underscore.
    mov(%1111_0000, al);
    or(%0000_1111, al);
    Answer:
  21. What is the value of AL after the following instructions? Write your answer in binary, preceding the binary value with % and separating each nibble with an underscore.
    mov(%1010_1010, al);
    or(%0101_0101, al);
    Answer:
  22. What is the value of AL after the following instructions? Write your answer in binary, preceding the binary value with % and separating each nibble with an underscore.
    mov(%1111_0000, al);
    xor(al, al);
    Answer:
  23. What is the value of AL after the following instructions? Write your answer in binary, preceding the binary value with % and separating each nibble with an underscore.
    mov(%1010_1010, al);
    xor(%0101_0101, al);
    Answer:
  24. What is the output of the following code?
    mov(%0111_1111, al);
    add(%0000_0001, al);
    if (@c) then
         stdout.put("OVERFLOW ");
    endif;
    stdout.put(al);
    Answer:
  25. What is the output of the following code?
    mov(%1010_1010, al);
    stdout.put("AL: ", (type int8 al), nl);
    not(al);
    add(1, al);
    stdout.put("AL: ", (type int8 al), nl);
    Answer:

Total points for this book learning challenge:

500 points