Exercise 8        Name _________________ Points  _    /20


 Give the Assembler to implement the following using both Array indexing and String operations.
 
Two Examples: Square all the 32 bit values in a 10 entry array using String Operations and Array indexing. 
.data
    src dword 24,8,0,13,5,-4,13,6,13,18
.code
main Proc  Far
    Mov    eCx, 10
    Mov    eSi, Offset src ; eSi = src
    Mov    eDi, Offset src ; eDi = src
    Cld
                           ; do {
do: LodsD                  ;   eAx = *eSi++
    Mul    eAx             ;   eAx = eAx * eAx
    StosD                  ;   *eDi++ = eAx
while:                     ; }while (--eCx!=0);
    loop   do

    invoke ExitProcess, 0
main endp
     End   main
.data
    src dword 24,8,0,13,5,-4,13,6,13,18

.code
main Proc  near
    Mov    eCx, 10
    Mov    eSi, Offset src; eSi = src
                         ; do {
do: Mov    eAx, [eSi]    ;   eAx = *eSi
    Mul    eAx           ;   eAx = eAx * eAx
    Mov    [eSi], eAx    ;   *eSi = eAx
    Add    eSi, 4        ;   eSi++
while:                   ; } while(--eCx!=0);
    loop   do

    invoke ExitProcess, 0
main endp
     End   main

1. (10)    Find the greatest 32 bit value in the src array and store in eAx. Hint: Use Scasd for string operation.
 
Array
        Mov    eCx, 10
        Mov    eDi, 0     
        Mov    eAx, src[0]
do:     
 if:    Cmp    eAx, src[eDi]
        Jl     then
        Jmp    endif
 then:  Mov    eAx, src[eDi]
 endif: 
        Add    eDi, 4
while:  Loop   do
endwhile:
Pointer
        Mov    eCx, 10
        Mov    eDi, Offset src     
        Mov    eAx, [eDi]
do:     
 if:    Cmp    eAx, [eDi]
        Jl     then
        Jmp    endif
 then:  Mov    eAx, [eDi]
 endif: 
        Add    eDi, 4
while:  Loop   do
endwhile:
String
        Mov    eCx, 10
        Mov    eDi, Offset src  
        Cld
        Mov    eAx, [eDi]
do:     
 if:    ScaSd
        Jl     then
        Jmp    endif
 then:  Mov    Ax, [eDi-4]
 endif: 
while:  Loop   do
endwhile:

2. (10)    Change all the entries that are 13 in array src to 10.
 
Array
        Mov    eCx, 10
        Mov    eDi, 0     
do:     
 if:    Cmp    src[eDi], 13
        Je     then
        Jmp    endif
 then:  Mov    src[eDi], 10
 endif: 
        Add    eDi, 4
while:  Loop   do
endwhile:




Pointer
        Mov    eCx, 10
        Mov    eDi, Offset src     
do:     
 if:    Cmp    word ptr [eDi], 13
        Je     then
        Jmp    endif
 then:  Mov    word ptr [eDi], 10
 endif: 
        Add    eDi, 4
while:  Loop   do
endwhile:




String
        Mov    eCx, 10
        Mov    eDi, Offset src  
        Cld
        
do:     Mov    eAx, 13
 if:    ScaSd
        Je     then
        Jmp    endif
 then:  Mov    eAx, 10
        Sub    eDi, 4
        StoSd  
 endif: 
while:  Loop   do
endwhile: