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

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 quotient 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;
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 quotient 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;
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 quotient 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;
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 quotient 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;
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 quotient 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;
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 quotient 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;
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);
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);
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);
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 uns8 variable?
mov(10, number);
mov(number, al);
cbw();
div(2, al);
11. What register does an x86 processor use to control its stack?
12. What will be the value of ESP after the following instruction is executed?
// GIVEN: ESP value starts at \$00FF_FFEA
push(eax);
13. What will be the value of ESP after the following instruction is executed?
// GIVEN: ESP value starts at \$00FF_FFEF
pop(eax);
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?
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);
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;

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);
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);
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);
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);
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);
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);
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);
24. What is the output of the following code?
mov(%0111_1111, al);
if (@c) then
stdout.put("OVERFLOW ");
endif;
stdout.put(al);