All pastes #673308 Raw Edit

Mine

public text v1 · immutable
#673308 ·published 2007-08-28 09:24 UTC
rendered paste body
# find the maximum in a set of numbers

.section .data
data:
.long 3,67,13,222,45,75,54,34,44,33,22,11,66,0

.section .text
.globl _start
.globl max
.globl data

_start:
pushl data # the argument for max is a pointer to a set of data items
call max
addl $4, %esp
movl %eax, %ebx # return the return value of max to the kernel
movl $1, %eax
int $0x80

.type max,@function
max:
pushl %ebp # prolog
movl %esp, %ebp

movl 8(%ebp), %edx # store the pointer to the data items in edx
xor %edi, %edi # edi is an index register
xor %ebx, %ebx # ebx is the largest number found so far
loop:
movl (%edx,%edi,4), %eax # retrieve the next number in eax
cmpl $0, %eax
je end_max
incl %edi
cmpl %ebx, %eax
jle loop
movl %eax, %ebx
jmp loop

end_max:
movl %ebx, %eax # return the highest found
movl %ebp, %esp # epilog
popl %ebp
ret