csci 10 :: book learning challenge 5 (due mon, sep 26)
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.

Questions:

Read Art of Assembly V3 10.2:

Your name:
  1. According to your text, why is zero/sign extending required for performing division on x86 processors?
    Answer:
  2. Write the code to do each of the following, using only the mov instruction:
    • zero extend an unsigned 8-bit numerator stored in AL into AX
    • zero extend an unsigned 16-bit numerator stored in AX into DX
    • zero extend an unsigned 32-bit numerator stored in EAX into EDX

    Answer:
  3. Write the code to do each of the following, using the "convert X to Y" instructions (to be discussed in class):
    • sign extend a signed 8-bit numerator stored in AL into AX
    • sign extend a signed 16-bit numerator stored in AX into DX
    • sign extend a signed 32-bit numerator stored in EAX into EDX

    Answer:
  4. After the following code executes, what register will contain the quotient, and what register will contain the remainder?
    div(10, edx:eax);
    Answer:
  5. Write the code to do each of the following, using movzx or movsx instructions (to be discussed in class):
    • move and zero extend the unsigned 8-bit numerator value stored in the variable value into AX
    • move and zero extend the unsigned 16-bit numerator value stored in the variable value into EAX
    • move and sign extend the signed 8-bit numerator value stored in the variable value into AX
    • move and sign extend the signed 16-bit numerator value stored in the variable value into EAX

    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 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;
    Answer:
  7. 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;
    Answer:
  8. 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;
    Answer:
  9. 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;
    Answer:
  10. 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;
    Answer:
  11. 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;
    Answer:
  12. What will happen if you execute the following HLA code (assume x has been properly declared as an uns8 variable)? What is the problem?
    mov(x, al);
    mov(0, ah);
    div(0, ax);
    Answer:
  13. Write all of the instructions needed to do the following:
    • test the variable x to see if it is an even or an odd number -- assume x has been properly declared as an uns32 variable)
    • if x is even, output "EVEN NUMBER"
    • if x is odd, output "ODD NUMBER"

    Answer:
  14. Write all of the instructions needed to do the following:
    • translate the following high level expression into assembly code, using only eax and edx (do not declare variables -- assume x and y have been properly declared as uns32 variables)
    x = (x + 5) / (y * 3);
    Answer:
  15. Write all of the instructions needed to do the following:
    • translate the following high level expression into assembly code, using only eax and edx (do not declare variables -- assume x and y have been properly declared as int32 variables)
    x = (x - 5) / (y * 3);
    Answer:

Total points for this book learning challenge:

150 points