CSci250 Assembly Language Programming: Homework 3 Solutions
Due date: Friday, October 31, 2008 in class
Each homework may have a different weight, which depends on its level of difficulty.
Absolutely no copying others' work

    Give an answer Error if the instructions contain errors or have faults.
         .data
         var1  SBYTE  -5, -2, -1, 1
         var2  WORD   0A01h, 8h, 0Bh, 200h
         var3  SWORD  3, -4
         var4  DWORD  8, 7
  1. What will be the hexadecimal value of the destination operand after each of the following instructions executes in sequence?     (10%)
         mov  ax, var3-1             ; a. ax = 0302h
    
         mov  ah, var2-2             ; b. ah = Error



  2. What will be the value of the destination operand after each of the following instructions executes in sequence?     (10%)
         movzx  edx, var2-1          ; b. edx =  00000101h
    
         movsx  edx, [var3+1]        ; d. edx = 0FFFFFC00h



  3. Where indicated, write down the values of the Carry, Sign, Zero, Overflow, and Parity flags after each instruction has executed:     (20%)
        mov  ax, 00FFh
        sub  ah, 1        ; CF = 1    SF = 1    ZF = 0    OF = 0    PF = 1
    
    
        neg  ah           ; CF = 1    SF = 0    ZF = 0    OF = 0    PF = 0
    
    
        add  al, 1        ; CF = 1    SF = 0    ZF = 1    OF = 0    PF = 1



  4. Write a sequence of two instructions that set both the Overflow and Sign flags, but not Carry flag.     (16%)
    Ans>



  5.     .data
        data1   LABEL  BYTE
        data2   WORD   10h, 5+2, 10
        array   DWORD  10 DUP (20 DUP(?)))
        string  BYTE   'a', 'b', 'c', 0
    Indicate the value of EAX after each instruction executes:     (16%)
        mov  eax, TYPE data1           ; EAX = 1
        mov  eax, LENGTHOF data1       ; EAX = 1
        mov  eax, SIZEOF data1         ; EAX = 1
        mov  eax, TYPE data2           ; EAX = 2
        mov  eax, LENGTHOF data2       ; EAX = 3
        mov  eax, SIZEOF data2         ; EAX = 6
        mov  eax, TYPE array           ; EAX = Error or 4 if the extra ) is not there
        mov  eax, LENGTHOF array       ; EAX = Error or 200 if the extra ) is not there
        mov  eax, SIZEOF array         ; EAX = Error or 800 if the extra ) is not there 
        mov  eax, TYPE string          ; EAX = 1
        mov  eax, LENGTHOF string      ; EAX = 4
        mov  eax, SIZEOF string        ; EAX = 4
       

  6.     myBytes1    BYTE   -2, 10, 20
        myWords1    WORD   30h, 0Ah
        myDoubles1  DWORD  1030h, 120h
        myPointer1  DWORD  myBytes1
    Fill in the requested register values on the right side of the following instruction sequence:     (16%)
         mov  esi, OFFSET myWords1
         mov  eax, DWORD PTR [esi+3]         ; EAX = 00103000h
    
         mov  ax,  WORD PTR myBytes1 + 2     ;  AX =     3014h
    
         mov  esi, myPointer1
         mov  eax, DWORD PTR [esi]           ; EAX = 30140AFEh
    
         mov  ax,  WORD PTR [esi+4]          ;  AX =     0A00h


  7. What will be the final value of EAX in this example?     (12%)
         mov   eax, 0
         mov   ecx, 2
     L1: mov   ebx, ecx
         mov   ecx, 2  
     L2: jmp   L4
     L3: inc   eax
         loop  L2
         mov   ecx, ebx
         loop  L1
     L4: jmp   L3
    Ans>