CMPS-2240 Homework 8 - Intro to x86 Assembly


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


1. Explain these inc, dec instructions
    dec eax 
    inc DWORD PTR [var]

2. Integer division utilizes a 64-bit register EDX:EAX (where EDX is the most significant 32 bits). The idiv instruction divides the contents of EDX:EAX by the operand. The quotient is stored into EAX and the remainder in EDX. Explain these operations:
    idiv ebx
    idiv DWORD PTR [var]

3. The bitwise logical AND, OR and EXCLUSIVE OR instructions perform the operation on the first register place the result in the first register. Explain these operations:
    and eax, 0fH   # 0fH  is 15 in decimal - the H denotes hex 
    xor edx, edx
    neg edx
    not edx

4. The Shift Left and Shift Right instructions perform shifts on the first operand, padding empty bit positions with zeros. The second operand is either an 8-bit constant or the register CL. Explain these shift operations:
    shl eax,1 
    shr ebx,cl

5. In x86, what does the instruction pointer (IP) register hold?

6. The unconditional jump instruction jumps to the given label. The conditional jump instruction jumps based on the contents of a condition bit in the machine status word register. This bit is set to 0 or 1 in the instruction prior to the conditional jump. Explain the control flow instructions below assuming that each is preceeded by cmp eax, ebx:
    jump L1 
    jle done
    je L1
    jge L1

7. The Compare (cmp) instruction compares the values of two operands and sets the condition codes in the machine status word appropriately. The result can then be used to facilitate a jump. Explain these:
      cmp eax, ebx   
      jle done

      cmp DWORD PTR [var], 10
      jeq loop 

8. What do the instructions below facilitate?
    call foo
    return