Created
March 28, 2012 17:16
-
-
Save ox/2228354 to your computer and use it in GitHub Desktop.
A function that is passed in an array of ints and the length of the array and tells you the greatest number in the array. eg: max(int numbers[], int len). Built on for i386, on a Mac, so you may need to change the labels (remove underscore), and the comme
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
.text | |
.globl _max | |
_max: | |
pushl %ebp | |
movl %esp, %ebp | |
movl 8(%ebp), %ecx #; assume first number is the greatest | |
movl %ecx, %eax #; eax points to the beggining of numbers[] | |
movl (%ecx), %ecx #; %ecx stores the highest number found | |
movl 12(%ebp), %edx #; len | |
jmp .compare | |
.new_greatest: | |
movl (%eax), %ecx | |
.loop: | |
decl %edx | |
addl $4, %eax | |
cmpl (%eax), %ecx | |
jl .new_greatest | |
.compare: | |
cmpl $1, %edx | |
jge .loop | |
movl %ecx, %eax | |
popl %ebp | |
ret |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment