maximum.s

#PURPOSE:		This program finds the maximum number of a
#				set of data items.
#
#VARIABLIES:	The registers have the following uses:
#
# %edi - Holds the index of the data item being examined
# %ebx - Largest data item found
# %eax - Current data item
#
# The following memory locations are used:
#
# data_items - contains the item data. A 0 is used
#			to terminate the data
#

.section .data

data_items:							#These are the data items
	.long 3,67,34,222,45,75,54,34,44,33,22,11,66,0

.section .text

.globl _start
_start:
	movl $0, %edi					# move 0 into the index register
	movl data_items(,%edi,4), %eax	# load the first byte of data
	movl %eax, %ebx					# since this is the first item, %eax is
									# the biggest

start_loop:							# start loop
	cmpl $0, %eax					# check to see if we've hit the end
	je loop_exit
	incl %edi						# load next value
	movl data_items(,%edi,4), %eax
	cmpl %ebx, %eax					# compare values
	jle start_loop					# jump to loop beginning if the new
									# one isn't bigger
	movl %eax, %ebx					# move the value as the largest
	jmp start_loop					# jump to loop beginning

loop_exit:
	# %ebx is startus code for the exit system call
	# and it already has the maximum number
	movl $1, %eax					# 1 is the exit() syscall
	int $0x80

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值