Skip to main content
Engineering LibreTexts

8.4: Exercises

  • Page ID
    19907
  • \( \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) Explain the difference between the following two instructions:

        1. mov     rdx, qword [qVar1]
        2. mov     rdx, qVar1

    2) What is the address mode of the source operand for each of the instructions listed below. Respond with Register, Immediate, Memory, or Illegal Instruction.

    Note,

            mov        <dest>, <source>
        mov    ebx, 14
        mov    ecx, dword [rbx]
        mov    byte [rbx+4], 10
        mov    10, rcx
        mov    dl, ah
        mov    ax, word [rsi+4]
        mov    cx, word [rbx+rsi]
        mov    ax, byte [rbx]  
    

    3) Given the following variable declarations and code fragment:

        ans1     dd 7
    
        mov      rax, 3
        mov      rbx, ans1
        add      eax, dword [rbx] 
    

    What would be in the eax register after execution? Show answer in hex, full register size.

    4) Given the following variable declarations and code fragment:

        list1     dd 2, 3, 4, 5, 6, 7
    
        mov rbx, list1
        add rbx, 4
        mov eax, dword [rbx] 
        mov edx, dword [list1]
    

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

    5) Given the following variable declarations and code fragment:

        lst         dd    2, 3, 5, 7, 9
    
                mov     rsi, 4 
                mov     eax, 1 
                mov     rcx, 2
        lp: add         eax, dword [lst+rsi]
                add     rsi, 4
                loop    lp
                mov     ebx, dword [lst]
    

    What would be in the eax, ebx, rcx, and rsi registers after execution? Show answer in hex, full register size. Note, pay close attention to the register sizes (32-bit vs. 64-bit).

    6) Given the following variable declarations and code fragment:

        list         dd     8, 6, 4, 2, 1, 0
                
                mov     rbx, list
                mov     rsi, 1
                mov     rcx, 3
                mov     edx, dword [rbx]
            lp: add     eax, dword [list+rsi*4]
                inc     rsi
                loop    lp 
                imu1    dword [list]
    

    What would be in the eax, edx, rcx, and rsi registers after execution? Show answer in hex, full register size. Note, pay close attention to the register sizes (32-bit vs. 64-bit).

    7) Given the following variable declarations and code fragment:

        list         dd     8, 7, 6, 5, 4, 3, 2, 1, 0
    
                mov     rbx, list
                mov     rsi, 0
                mov     rcx, 3
                mov     edx, dword [rbx]
            lp: add     eax, dword [list+rsi*4]
                inc     rsi
                loop    lp
                cdq
                idiv    dword [list]
    

    What would be in the eax, edx, rcx, and rsi registers after execution? Show answer in hex, full register size. Note, pay close attention to the register sizes (32-bit vs. 64-bit).

    8) Given the following variable declarations and code fragment:

        list         dd     2, 7, 4, 5, 6, 3
        
                mov     rbx, list
                mov     rsi, 1
                mov     rcx, 2
                mov     eax, 0
                mov     edx, dword [rbx+4]
            lp: add     eax, dword [rbx+rsi*4]
                add     rsi, 2
                loop    lp
                imu1    dword [rbx]
    

    What would be in the eax, edx, rcx, and rsi registers after execution? Show answer in hex, full register size. Note, pay close attention to the register sizes (32-bit vs. 64-bit).

    Suggested Projects

    Below are some suggested projects based on this chapter.

    1) Implement the example program to sum a list of numbers. Use the debugger to execute the program and display the final results. Create a debugger input file to show the results.

    2) Update the example program from the previous question to find the maximum, minimum, and average for the list of numbers. Use the debugger to execute the program and display the final results. Create a debugger input file to show the results.

    3) Implement the example program to compute the lateral total surface area (including the base) and volume of each square pyramid in a set of square pyramids. Once the values are computed, the program finds the minimum, maximum, sum, and average for the total surface areas and volumes. Use the debugger to execute the program and display the final results. Create a debugger input file to show the results.

    4) Write an assembly language program to find the minimum, middle value, maximum, sum, and integer average of a list of numbers. Additionally, the program should also find the sum, count, and integer average for the negative numbers. The program should also find the sum, count, and integer average for the numbers that are evenly divisible by 3. Unlike the median, the 'middle value' does not require the numbers to be sorted. Note, for an odd number of items, the middle value is defined as the middle value. For an even number of values, it is the integer average of the two middle values. Assume all data is unsigned. Use the debugger to execute the program and display the final results. Create a debugger input file to show the results.

    5) 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.

    6) Create a program to sort a list of numbers. Use the following bubble sort38

    algorithm:

               for ( i = (len-1) to 0 ) {
                    swapped = false               
                    for ( j = 0 to i-1 )
                        if ( lst(j) > lst(j+1) ) {                        
                            tmp = lst(j)
                            lst(j) = lst(j+1)
                            lst(j+1) = tmp
                            swapped = true                   
                        }
                    if ( swapped = false ) exit
                } 

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


    This page titled 8.4: Exercises is shared under a CC BY-NC-SA license and was authored, remixed, and/or curated by Ed Jorgensen.

    • Was this article helpful?