CMPS-2240 Homework 7 - Intro to x86 Assembly


The answers to the questions below are found in this x86-64 assembly guide and PPT PDF


1. What are the ESP and the EBP registers in x86 assembly used for?

2. The 6 general purpose registers (GPRs) in x86 are EAX, EBX, ECX, EDX, ESI, & EDI. There are also sub-registers. For example, explain the difference between the EAX, AX, AH and AL registers. Give the size of each.

3. Describe what these declarations in the static data segment accomplish. Note that in x86 a word is 2 bytes and a double word is 4 bytes.
   .DATA
   var DB 64 
   var2  DB ? 
   DB 10     
   X  DW ?  
   Y  DD 3000

4. The DUP assembler directive duplicates an initialization. Explain these:
    Z  DD 1, 2, 3
    bytes DB 10 DUP(?)
    arr  DD 100 DUP(0) 
    str  DB 'hello',0

5. Unlike MIPS, x86 supports direct accesses to memory. Note that a WORD is 2 bytes and a DWORD is 4 bytes. The x86 registers EAX, EBX, ECX, EDX, ESI, EDI, ESP, and EBP are 32-bit. Also note that with x86, data movement is always from right to left (there is no operation equivalent to the store operation in x86). With these facts in mind, explain the instructions below.
    mov eax, [ebx]   
    mov [edx], eax   
    mov eax, [esi-4] 
    mov [esi+eax], cl 
    mov BYTE PTR [ebx], 12 
    mov WORD PTR [ebx], 5 
    mov DWORD PTR [ebx], 9

6. The MOV instruction supports register to memory, register to register or memory to register. Explain these:
    mov eax, ebx 
    mov byte ptr [var], 5

7. The push instruction places its operand onto the top of the hardware supported stack in memory. Push first decrements ESP by 4 (bytes), then places its operand into the contents of the 32-bit location at address [ESP]. ESP (the stack pointer) is decremented by push first since the x86 stack grows from high to low addresses. Explain these instructions:
  push eax  
  push [var]

8. The pop instruction copies 4 bytes from the top of the hardware stack at address SP to register or memory. SP is then incremented by 4. Explain these instructions:
    pop edi
    pop [ebx]

9. The Load Effective Address instruction (lea) grabs the address of a label/symbol or computes an address by adding an offset. The effective address is then loaded into the target register. Explain these:
    lea eax, [var] 
    lea edi, [ebx+4*esi]

10. Unlike MIPS, arithmetic operations in x86 can be performed register to register or register to memory. The second operand may be a constant. Explain these:
    add eax, 10 
    add BYTE PTR [var], 10 
    sub al, ah 
    imul eax, [var]
    imul esi, edi, 25