Assignment 

For this program you will find the largest element in an array of DWORDs.

The output of your program will be:

The Largest Integer In the Array is: +6

where, for the example I used, the largest element in the array is 6.  You will make up your own array of integers with at least 6 integers, and including some duplicate values.

You will do all of your work using registers, i.e. NO variables appear in your code except to initialize registers once.

You code must include:

Meaningful simultaneous use of EAX, EBX, ECX, EDX

at least three jump instructions

at least two compare instructions

at least one meaningful use of LENGTHOF

at least one meaningful use of TYPE

at least one meaningful use of OFFSET

at least one meaningful use of indirect addressing

use of WriteString and WriteInt from the NoIrvine library

 Solution

INCLUDE Irvine32.inc

.data

array DWORD 12,4,32,45,55,3,100,55,9,44

result      BYTE  ‘The Largest Integer In the Array is: ‘,0

.code

main PROC

movebx,OFFSET array     ; load offset of array into ebx

movecx,[ebx]                  ; ecx will contain the largest element, take the first element as the initial guess

movedx,LENGTHOF array   ; load length of array in edx for using it as counter in a loop

search:

cmp edx,0                     ; see if the count reached zero

jle done                      ; if it’s less or equal than zero,  exit the loop

moveax,[ebx]                  ; load element at current address in ebx into eax

cmpeax,ecx                    ; see if the element we loaded is greater than the previous largest value

jle   smaller                       ; if it’s smaller, skip next instruction

movecx,eax                    ; else, save current element as the largest

smaller:

addebx,TYPE array       ; increment ebx by the element type to go to next array element

decedx                              ; decrement edx, which is the number of remaining elements

jmp search                    ; repeat the search cycle

done:

movedx,OFFSET result    ; print the result message

callWriteString

moveax,ecx                    ; put the maximum value we found in eax for printing it

callWriteInt

callCrLf                      ; print a new line

exit                          ; exit the program

main ENDP

END main