Created
April 26, 2015 05:24
-
-
Save joshtwo/1736076c5dd3d24d614e to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
; find the maximum number in a list | |
; | |
; variables | |
; edi - Holds the index of the array | |
; ebx - Largest number | |
; eax - Current element | |
section .data | |
array: | |
dd 3,67,342,222,45,75,54,34,44,33,22,11,66,0 | |
section .text | |
global _start | |
_start: | |
mov edi, 0 ; set the index to 0 | |
mov eax, [edi * 4 + array] ; set eax to the first element | |
mov ebx, eax ; set the max to the first element to start with | |
start_loop: | |
cmp eax, 0 ; see if we're at the last element, 0 | |
je loop_exit ; if we are, jump to the loop exit | |
inc edi ; increment the index | |
mov eax, [edi * 4 + array] ; set the current element to the new element | |
cmp eax, ebx ; compare eax to ebx | |
jle start_loop ; if the new element is less than the max, continue the looping | |
mov ebx, eax ; otherwise set the new max to the current element | |
jmp start_loop ; whether or not we executed the previous instruction, we | |
; still need to go back to the beginning of the loop | |
loop_exit: ; return the max element using the exit system call | |
mov eax, 1 ; set the system call to exit (1) | |
int 80h ; ebx is already set to the max element |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment