Skip to main content
Engineering LibreTexts

7.9: Exercises

  • Page ID
    57690
  • \( \newcommand{\vecs}[1]{\overset { \scriptstyle \rightharpoonup} {\mathbf{#1}} } \) \( \newcommand{\vecd}[1]{\overset{-\!-\!\rightharpoonup}{\vphantom{a}\smash {#1}}} \)\(\newcommand{\id}{\mathrm{id}}\) \( \newcommand{\Span}{\mathrm{span}}\) \( \newcommand{\kernel}{\mathrm{null}\,}\) \( \newcommand{\range}{\mathrm{range}\,}\) \( \newcommand{\RealPart}{\mathrm{Re}}\) \( \newcommand{\ImaginaryPart}{\mathrm{Im}}\) \( \newcommand{\Argument}{\mathrm{Arg}}\) \( \newcommand{\norm}[1]{\| #1 \|}\) \( \newcommand{\inner}[2]{\langle #1, #2 \rangle}\) \( \newcommand{\Span}{\mathrm{span}}\) \(\newcommand{\id}{\mathrm{id}}\) \( \newcommand{\Span}{\mathrm{span}}\) \( \newcommand{\kernel}{\mathrm{null}\,}\) \( \newcommand{\range}{\mathrm{range}\,}\) \( \newcommand{\RealPart}{\mathrm{Re}}\) \( \newcommand{\ImaginaryPart}{\mathrm{Im}}\) \( \newcommand{\Argument}{\mathrm{Arg}}\) \( \newcommand{\norm}[1]{\| #1 \|}\) \( \newcommand{\inner}[2]{\langle #1, #2 \rangle}\) \( \newcommand{\Span}{\mathrm{span}}\)\(\newcommand{\AA}{\unicode[.8,0]{x212B}}\)

    Below are some quiz questions and suggested projects based on this chapter.

    Questions

    Below are some quiz questions based on this chapter.

    1) Which of the following instructions is legal / illegal? As appropriate, provide an explanation.

    1. mov     rax, 54
    2. mov     ax, 54
    3. mov     al, 354
    4. mov     rax, r11
    5. mov     rax, r11d
    6. mov     54, ecx
    7. mov     rax, qword [qVar]
    8. mov     rax, qword [bVar]
    9. mov     rax, [qVar]
    10. mov    rax, qVar
    11. mov    eax, dword [bVar]
    12. mov    qword [qVar2], qword [qVar1]
    13. mov    qword [bVar2], qword [qVar1]
    14. mov    r15, 54
    15. mov    r16, 54
    16. mov    r11b, 54
    

    2) Explain what each of the following instructions does.

    1. movzx     rsi, byte [bVar1]
    2. movsx     rsi, byte [bVar1]

    3) What instruction is used to:

    1. convert an unsigned byte in al into a word in ax.
    2. convert a signed byte in al into a word in ax.

    4) What instruction is used to:

    1. convert an unsigned word in ax into a double-word in eax.
    2. convert a signed word in ax into a double-word in eax.

    5) What instruction is used to:

    1. convert an unsigned word in ax into a double-word in dx:ax.
    2. convert a signed word in ax into a double-word in dx:ax.

    6) Explain the difference between the cwd instruction and the movsx instructions.

    7) Explain why the explicit type specification (dword in this example) is required on the first instruction and is not required on the second instruction.

    1. add    dword [dVar], 1
    2. add    [dVar], eax

    8) Given the following code fragment:

        mov    rax, 9
        mov    rbx, 2
        add    rbx, rax
    

    What would be in the rax and rbx registers after execution? Show answer in hex, full register size.

    9) Given the following code fragment:

        mov    rax, 9
        mov    rbx, 2
        sub    rax, rbx

    What would be in the rax and rbx registers after execution? Show answer in hex, full register size.

    10) Given the following code fragment:

        mov    rax, 9
        mov    rbx, 2
        sub    rbx, rax
    

    What would be in the rax and rbx registers after execution? Show answer in hex, full register size.

    11) Given the following code fragment:

        mov    rax, 4
        mov    rbx, 3
        imu1   rbx

    What would be in the rax and rdx registers after execution? Show answer in hex, full register size.

    12) Given the following code fragment:

        mov    rax, 5
        cqo
        mov    rbx, 3
        idiv   rbx

    What would be in the rax and rdx registers after execution? Show answer in hex, full register size.

    13) Given the following code fragment:

              mov   rax, 11
              cqo
              mov   rbx, 4
              idiv  rbx
    

    What would be in the rax and rdx registers after execution? Show answer in hex, full register size.

    14) Explain why each of the following statements will not work.

        1. mov    42, eax
        2. div    3
        3. mov    dword [num1], dword [num1]
        4. mov    dword [ax], 800
    

    15) Explain why the following code fragment will not work correctly.

              mov    eax, 500
              mov    ebx, 10
              idiv   ebx
    

    16) Explain why the following code fragment will not work correctly.

              mov   eax, -500
              cdq
              mov    ebx, 10
              div    ebx
    

    17) Explain why the following code fragment will not work correctly.

              mov    ax, -500
              cwd
              mov    bx, 10
              idiv   bx
              mov    dword [ans], eax
    

    18) Under what circumstances can the three-operand multiple be used?

    Suggested Projects

    Below are some suggested projects based on this chapter.

    1) Create a program to compute the following expressions using unsigned byte variables and unsigned operations. Note, the first letter of the variable name denotes the size (b → byte and w → word).

    Use the debugger to execute the program and display the final results. Create a debugger input file to show the results in both decimal and hexadecimal.

    1. bAns1 = bNum1 + bNum2
    2. bAns2 = bNum1 + bNum3
    3. bAns3 = bNum3 + bNum4
    4. bAns6 = bNum1 – bNum2
    5. bAns7 = bNum1 – bNum3
    6. bAns8 = bNum2 – bNum4
    7. wAns11 = bNum1 * bNum3
    8. wAns12 = bNum2 * bNum2
    9. wAns13 = bNum2 * bNum4
    10. bAns16 = bNum1 / bNum2
    11. bAns17 = bNum3 / bNum4
    12. bAns18 = wNum1 / bNum4
    13. bRem18 = wNum1 % bNum4

    2) Repeat the previous program using signed values and signed operations. Use the debugger to execute the program and display the final results. Create a debugger input file to show the results in both decimal and hexadecimal.

    3) Create a program to complete the following expressions using unsigned word sized variables. Note, the first letter of the variable name denotes the size (w → word and d → double-word).

    1. wAns1 = wNum1 + wNum2
    2. wAns2 = wNum1 + wNum3
    3. wAns3 = wNum3 + wNum4
    1. wAns6 = wNum1 – wNum2
    2. wAns7 = wNum1 – wNum3
    3. wAns8 = wNum2 – wNum4
    4. dAns11 = wNum1 * wNum3
    5. dAns12 = wNum2 * wNum2
    6. dAns13 = wNum2 * wNum4
    7. wAns16 = wNum1 / wNum2
    8. wAns17 = wNum3 / wNum4
    9. wAns18 = dNum1 / wNum4
    10. wRem18 = dNum1 % wNum4

    Use the debugger to execute the program and display the final results. Create a debugger input file to show the results in both decimal and hexadecimal.

    4) Repeat the previous program using signed values and signed operations. Use the debugger to execute the program and display the final results. Create a debugger input file to show the results in both decimal and hexadecimal.

    5) Create a program to complete the following expressions using unsigned double- word sized variables. Note, the first letter of the variable name denotes the size (d → double-word and q → quadword).

    1. dAns1 = dNum1 + dNum2
    2. dAns2 = dNum1 + dNum3
    3. dAns3 = dNum3 + dNum4
    4. dAns6 = dNum1 – dNum2
    5. dAns7 = dNum1 – dNum3
    6. dAns8 = dNum2 – dNum4
    7. qAns11 = dNum1 * dNum3
    8. qAns12 = dNum2 * dNum2
    9. qAns13 = dNum2 * dNum4
    10. dAns16 = dNum1 / dNum2
    11. dAns17 = dNum3 / dNum4

    12. dAns18 = qNum1 / dNum4

    13. dRem18 = qNum1 % dNum4
    Use the debugger to execute the program and display the final results. Create a

    debugger input file to show the results in both decimal and hexadecimal.

    6) Repeat the previous program using signed values and signed operations. Use the debugger to execute the program and display the final results. Create a debugger input file to show the results in both decimal and hexadecimal.

    7) Implement the example program to compute the sum of squares from 1 to n. Use the debugger to execute the program and display the final results. Create a debugger input file to show the results in both decimal and hexadecimal.

    8) Create a program to compute the square of the sum from 1 to n. Specifically, compute the sum of integers from 1 to n and then square the value. Use the debugger to execute the program and display the final results. Create a debugger input file to show the results in both decimal and hexadecimal.

    9) Create a program to iteratively find the nth Fibonacci number(For more information, refer to: http://en.Wikipedia.org/wiki/Fibonacci_number). The value for n should be set as a parameter (e.g., a programmer defined constant). The formula for computing Fibonacci is as follows:

    \[fibonacci(n) = \begin{cases} n & \text{if } n = 0 \text{ or } n = 1 \\ fibonacci (n - 2) + fibonacci (n - 1) & \text{if } n \ge 2 \end{cases}\nonumber\]

    Use the debugger to execute the program and display the final results. Test the program for various values of n. Create a debugger input file to show the results in both decimal and hexadecimal.


    7.9: Exercises is shared under a not declared license and was authored, remixed, and/or curated by LibreTexts.

    • Was this article helpful?