Skip to main content
Engineering LibreTexts

12.10: 12.13-Exercises

  • Page ID
    58318
  • \( \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) What are the two main actions of a function call?

    2) What are the two instructions that implement linkage?

    3) When arguments are passed using values, it is referred to as?

    4) When arguments are passed using addresses, it is referred to as?

    5) If a function is called fifteen (15) times, how many times is the code placed in memory by the assembler?

    6) What happens during the execution of a call instruction (two things)?

    7) According to the standard calling convention, as discussed in class, what is the purpose of the initial pushes and final pops within most procedures?

    8) If there are six (6) 64-bit integer arguments passed to a function, where specifically should each of the arguments be passed?

    9) If there are six (6) 32-bit integer arguments passed to a function, where specifically should each of the arguments be passed?

    10) What does it mean when a register is designated as temporary?

    11) Name two temporary registers?

    12) What is the name for the set of items placed on the stack as part of a function call?

    13) What does it mean when a function is referred to as a leaf function?

    14) What is the purpose of the add rsp, <immediate> after the call statement?

    15) If three arguments are passed on the stack, what is the value for the <immediate>?

    16) If there are seven (7) arguments passed to a function, and the function itself pushes the rbp, rbx, and r12 registers (in that order), what is the correct offset of the stack-based argument when using the standard calling convention?

    17) What, if any, is the limiting factor for how many times a function can be called?

    18) If a function must return a result for the variable sum, how should the sum variable be passed (call-by-reference or call-by-value)?

    19) If there are eight (8) arguments passed to a function, and the function itself pushes the rbp, rbx, and r12 registers (in that order), what are the correct offsets for each of the two stack-based arguments (\(7^{th}\) and \(8^{th}\)) when using the standard calling convention?

    20) What is the advantage of using stack dynamic local variables (as opposed to using all global variables)?

    Suggested Projects

    Below are some suggested projects based on this chapter.

    1) Create a main and implement the stats1 example function. Use the debugger to execute the program and display the final results. Create a debugger input file to show the results.

    1. 2) Create a main and implement the stats2 example function. Use the debugger to execute the program and display the final results. Create a debugger input file to show the results.
    2. 3) Create a main program and a function that will sort a list of numbers in ascending order. Use the following selection(For more information, refer to: http://en.Wikipedia.org/wiki/Selection_sort) sort algorithm:

    begin for

     begin 
         for   i = 0 to len-1
              small = arr(i)
              index = i
              for  j = i to len-1 
                  if ( arr(j) < small ) then
                      small = arr(j)       
                      index = j
                  end_if
              end_for
              arr(index) = arr(i)
              arr(i) = small            
         end_for
    end_begin
    

    The main should call the function on at least three different data sets. Use the debugger to execute the program and display the final results. Create a debugger input file to show the results.

    4) Update the program from the previous question to add a stats function that finds the minimum, median, maximum, sum, and average for the sorted list. The stats function should be called after the sort function to make the minimum and maximum easier to find. Use the debugger to execute the program and display the final results. Create a debugger input file to show the results.

    5) Update the program from the previous question to add an integer square root function and a standard deviation function. To estimate the square root of a number, use the following algorithm:

    \[\begin{array} {rcl} {iSqrt_{est}} & = & {iNumber} \\ {iSqrt_{est}} & = & {\dfrac{(\dfrac{iNumber}{iSqrt_{est}})+iSqrt_{est}}{2}} \end{array} \ \ \text{iterate 50 times}\nonumber\]

    The formula for standard deviation is as follows:

    \[iStandardDeviation = \sqrt{\dfrac{\sum_{i = 0}^{length - 1} (list[i] - average)^2}{length}}\nonumber\]

    Note, perform the summation and division using integer values. Use the debugger to execute the program and display the final results. Create a debugger input file to show the results.

    6) Convert the integer to ASCII macro from the previous chapter into a void function. The function should convert a signed integer into a right-justified string of a given length. This will require including any leading blanks, a sign (“+” or “-”), the digits, and the NULL. The function should accept the value for the integer and the address of where to place the NULL terminated string, and the value of the maximum string length - in that order. Develop a main program to call the function on a series of different integers. The main should include the appropriate data declarations. Use the debugger to execute the program and display the final results. Create a debugger input file to show the results.

    7) Create a function to convert an ASCII string representing a number into an integer. The function should read the string and perform appropriate error checking. If there is an error, the function should return FALSE (a defined constant set to 0). If the string is valid, the function should convert the string into an integer. If the conversion is successful, the function should return TRUE (a defined constant set to 1). Develop a main program to call the function on a series of different integers. The main should include the appropriate data declarations and applicable the constants. Use the debugger to execute the program and display the final results. Create a debugger input file to show the results.


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

    • Was this article helpful?