CSc 343
Computer Organization and Programming
Spring Quarter 1998
Solutions to Quiz #4 (22 May 1998, Friday)


1. Suppose that the data segment contains the following (hex) bytes,
   starting at offset 0:

   Offset:   00 01 02 03 04 05 06 07 08 09 0A 0B 0C 0D 0E 0F 
   Contents: 30 31 32 33 34 35 36 37 38 39 3A 3B 3C 3D 3E 3F

   Assume that the DS and ES registers both point to the beginning
   of the data segment. Show the (hex) contents of the CX, SI, and DI
   registers after all of the following instructions are executed. 
   Also show the final contents of the data segment.

  CLD                          CX: ___0000_______
  MOV  CX,4
  MOV  SI,02H                  SI: ___000A_______
  MOV  DI,08H
  REP  MOVSW                   DI: ___0010_______

   Offset:   00 01 02 03 04 05 06 07 08 09 0A 0B 0C 0D 0E 0F 
   Contents: 30 31 32 33 34 35 36 37 32 33 34 35 36 37 32 33

2. What will be the value of DI (in hex) at the end of the following
   code fragment? Assume that the dest is at offset 0006h in the data segment.

dest   db    'XXXXAXXXX'


   cld
   mov  al,'A'
   mov  di,offset dest
   mov  cx,9
   repnz scasb


   DI = __000B____


3. Write a procedure that counts the number of vowels in a string defined 
   in the data segment.  Consider the following declarations for your 
   procedure.

   mystring db 'this is a test of the string operations','$'
   vowels db 'AaEeIiOoUu'
   nvowels dw ?

   The procedure should put the result in the variable nvowels. You must 
   use the string operation scasb for comparing with the vowels.

  vowelcount proc near
     cld
     lea  si,mystring
     mov  nvowles,0
 l1: lodsb
     cmp  al,'$'
     je   done
     lea  di,vowels
     mov  cx,10
     repne scasb
     jne   l1
     inc  nvowels
     jmp  l1
done: ret
vowelcount endp