Assignment #5: Intel x86 Assembly, Procedures, and the Stack Frame

Contents:


Overview

Topic: The Intel x86 ISA, x86 Assembly Programming, Procedure Calls, and the Stack Frame
Related Reading: class notes and Chapter 3 (esp. sections 3.7 and 3.8)


Practice Problems

Practice problems from the textbook (answers are at the end of the chapter):


Problems to be Submitted (25 points)

When you turn in your assignment, you must include a signed cover sheet (PDF version) with your assignment (you're assignment will not be graded without a completed cover sheet).

You are allowed to submit your assignment via email, but if you choose to do so, you must bring a hardcopy of your assignment along with a completed cover sheet to the instructor at the next class. (Note: Do not email the instructor any .zip file attachments, as SLU's email may not accept these emails; i.e. the instructor may not receive your email.)

  1. (2 points)

    What operation is performed by the following sequence of instructions?

          pushw  %ax 
          pushw  %dx 
          popw   %ax 
          popw   %dx 
    

  2. (2 points)

    Given the four major sections of a process' memory organization (Text, Data, Heap, and Stack), indicate which area each of the following are stored in:

    1. local variables
    2. program code
    3. dynamically-allocated variables, instantiated via new or malloc()
    4. global variables

  3. (9 points)

    Given the following code:

    
          snippet:
                pusha
                pushl $100
                pushl $25
                pushl $7
                call SomeProcedure
                pop   %eax
                pop   %eax
                pop   %eax
                popa
                ret
    
          SomeProcedure:
                pushl %ebp
                movl  %esp, %ebp
                movl  8(%ebp), %eax
                movl  12(%ebp), %ebx
                movl  16(%ebp), %edx  #Part D below refers to this line
                cmpl  %ebx, %eax
                jle   L1
                subl  %ebx, %eax
                jmp   L2
    
             L1:
                subl  %eax, %ebx
                movl  %ebx, %eax
    
             L2:
                movl  $0, %ecx
                addl  %eax, %ecx
                addl  %ecx, %edx
                leave
                ret
    
    1. (2 points)

      With respect to SomeProcedure:

      • How many input args are there?   How are they passed in?
      • How many outputs are there?   How are they passed out?

    2. (2 points)

      What does this procedure do?   Give an equation in terms of the inputs...

    3. (1 point)

      What is the purpose of the pusha and popa instructions?

    4. (4 points)

      Supposing that SomeProcedure is called from snippet, draw the program stack from 16(%ebp) to (%ebp) after executing instruction movl 16(%ebp), %edx. Also, give the contents of the registers EAX, EBX, ECX, and EDX as of the same line.

  4. (12 points)

    Submit via email, if you haven't already, your six in-class programming assignments.