pgubook-readers
[Top][All Lists]
Advanced

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

[Pgubook-readers] Exercise Chapter 4 - Maximum modified


From: Horacio
Subject: [Pgubook-readers] Exercise Chapter 4 - Maximum modified
Date: Thu, 7 Apr 2005 01:19:47 -0300
User-agent: KMail/1.8

Hi!, I'm going to introduce myself before starting with the questions. My name 
is Horacio and I live in Argentina. I've been reading the book and making all 
the exercises, but there's one that keep me asleep at night.
Chapter 4. modify the maximun program from chapter 3, replace the loop with a 
function that recives a pointer to the data_items. (Actualy, you'll have to 
pass the function 3 lists and it' will return the maximum number from the 
last one, but I'm putting it shorter in order to get the point)

Here is my program, but I'll mark the point were i cant understand what to do

#Purpouse: Finds the maximum number on a list
#
#Function maximo recives the pointer to the data_items
#
#               %eax = holds number being examined
#               %ebx = holds maximum number
#               %ecx = pointer to data 

.section .data

data_items:
.long 3,67,34,222,45,54,34,44,33,22,11,66,0

.section .text

.globl _start
_start:

movl $data_items, %ecx          #makes %ecx pointer
movl %ecx, %ebx                 #makes first number in list the maximum one
call maximo

movl $1, %eax
int $0x80

.type maximo, @function
maximo:

pushl %ebp
movl %esp, %ebp
cmpl $0, %ecx                           #checks if we have reached the end of 
the list
je salir_maximo                         #if it's true we exit de function

addl $4, %ecx                           #moves the pointer to the next value

movl (%ecx), %eax                       #moves the value to %eax, this could be 
ommited
                                                #compared directly to ebx
cmpl %eax, %ebx
jle ############                #This is the point were I don't know how to do 
it
                                                #I'll need to jump to the 
beggining of the function and
                                                #make all the loop again. I'd 
tried with je call maximo but
                                                #it failed, also je maximo and 
also.

movl %eax, %ebx                 #makes %eax the maximum value
#############                   #Here I will also need to make all the loop 
again

salir_maximo:
movl %ebp, %esp
popl %ebp
ret

I've tried a lot of thing before calling for help, but I feel that the answer 
is easy and I've been missing something.

Thank You!



reply via email to

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