problem
You are to, given the data below, design an IA-32 assembly language program to find the max and min of the array in X and save them in A and B respectively.
X sword 100,200,-100,-200,150,-150,300,250
A sword ?
B sword ?
what i have so far:
1. irvine32.inc
2. .data
3. x sword 100, 200, -100, -200, 150, -150, 300, 250
4. A sword ?
5. B sword ?
6. . code
7. begin
8. mov esi, offset x ; esi is the base of x
9. mov aX, 0
10. mov ecx, lengthof x ; ecx = counter
11. next
12. mov ax, [esi] ; ax is the first value of x
13. add esi, Type x ; how many bytes a member of an array takes
14. loop next ; go to start of loop for the next comparison
15. mov esi, offset x ; location of x
16. mov ax, [esi] ; first value of x
17. mov ecx, lengthof x ; number of elements in x
18. greatest: cmp ax, [esi] ; compare ax and esi
19. jl lesser ; if ax < [esi], skip to lesser
20. mov ax, [esi] ; if ax > [esi], store [esi] to ax
21. lesser:
22. add esi, type x ; offsets esi to the next element
23. loop next ; loops until esi is at ecx
24. mov A, ax ; store the greatest value in A
25. jmp smallest ; jump to smallest comparison
26. smallest: cmp ax, [esi] ; compare ax and esi
27. jg greater ; if ax > [esi], skip to greater
28. mov ax, [esi] ; if ax < [esi], store [esi] to ax
29. greater :
30. add esi, type x ; offset esi to the next element
31. loop next ; loops until esi is at ecx
32. mov B, ax ; store the smallest value in B
33. invoke exitProcess, 0
34. end begin