Skip to main content
Engineering LibreTexts

9.5: Exercises

  • Page ID
    19915
  • \( \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 register refers to the top of the stack?
    2. What happens as a result of a push rax instruction (two things)?
    3. How many bytes of data does the pop rax instruction remove from the stack?
    4. Given the following code fragment:
        mov     r10, 1 
        mov     r11, 2 
        mov     r12, 3 
        push    r10 
        push    r11 
        push    r12 
        pop     r10
        pop     r11 
        pop     r12

    What would be in the r10 , r11, and r12 registers after execution? Show answer in hex, full register size.

    1. Given the following variable declarations and code fragment:
        lst     dq    1, 3, 5, 7, 9
        
                mov     rsi, 0 
                mov     rcx, 5
        lp1:    push    qword [lst+rsi*8]
                inc     rsi
                loop    lp1 
                mov     rsi, 0 
                mov     rcx, 5
        lp2:    pop     qword [lst+rsi*8]
                inc     rsi
                loop    lp2
                mov     rbx, qword [lst]
    

    Explain what would be the result of the code (after execution)?

    1. Provide one advantage to the stack growing downward in memory.

    Suggested Projects

    Below are some suggested projects based on this chapter.

    1. Implement the example program to reverse 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. Create a program to determine if a NULL terminated string representing a word is a palindrome(For more information, refer to: http://en.Wikipedia.org/wiki/Palindrome). A palindrome is a word that reads the same forward or backwards. For example, “anna”, “civic”, “hannah”, “kayak”, and “madam” are palindromes. This can be accomplished by pushing the characters on the stack one at a time and then comparing the stack items to the string starting from the beginning. Use the debugger to execute the program and display the final results. Create a debugger input file to show the results.
    3. Update the previous program to test if a phrase is a palindrome. The general approach using the stack is the same, however, spaces and punctuation must be skipped. For example, “A man, a plan, a canal – Panama!” is a palindrome. The program must ignore the comma, dash, and exclamation point. Use the debugger to execute the program and display the final results. Create a debugger input file to show the results.

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

    • Was this article helpful?