pgubook-readers
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Pgubook-readers] Chapter 3, Concepts, Stuck


From: Tim Hilton
Subject: [Pgubook-readers] Chapter 3, Concepts, Stuck
Date: 11 Feb 2004 01:02:46 -0500

#PURPOSE:       This program finds the max number
#

#VARIABLES:     %edi holds index of item being examined
#               %ebx max data item found
#               %eax current data item
#               %ecx holds current data_items pointer
#               %edx holds ending data_items address
#
#               Memory locations:
#               data_items - contains the data items.
#               data_end - marks end of data_items addresses
#               an address is used to terminate the data
#

.section .data

data_items:             # these are the data items
.long 3,67,34,222,2,254,54,34,44,1,22,11,8
data_end:               # marks end address of data_items
.long 0

.section .text

.globl _start

_start:
movl $0, %edi                   # move 0 into index register
movl data_items, %ecx           # initial data_items pointer
movl data_end, %edx             # end of data_items address
movl data_items(,%edi,4), %eax  # load the first byte of data
movl %eax, %ebx                 # %eax is max now

start_loop:                     # start loop
addl $4, %ecx                   # add 4 to data_items pointer
cmpl %edx, %ecx                 # see if this is the end address
je loop_exit                    # if it is exit loop
incl %edi                       # load next value
movl data_items(,%edi,4), %eax
cmpl %ebx, %eax                 # compare values
jle start_loop                  # jump to the loop beginning
                                # if %eax is not bigger
movl %eax, %ebx                 # move %eax as max value
jmp start_loop                  # jump to loop beginning

loop_exit:
# %ebx is status code for exit sys call, and contains max number
movl $1, %eax                   # 1 is exit() sys call
int $0x80





reply via email to

[Prev in Thread] Current Thread [Next in Thread]