|
From: | Justis Durkee |
Subject: | Re: [Pgubook-readers] Exercise Chapter 4 - Maximum modified |
Date: | Thu, 07 Apr 2005 00:23:04 -0700 |
User-agent: | Mozilla Thunderbird 1.0 (Windows/20041206) |
Horacio wrote:
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)You have set %ecx to a pointer, yet here you are comparing a constant(0) to %ecx. This loop will most likely end in a segmentation fault, as it will increment %ecx into unknown memory locations. You probably want to indirectly address %ecx as (%ecx).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 cmpl $0, %ecx #checks if we have reached the end of the list
Here you want to jump to the beginning of the loop instead of the function as you wouldn't want to adjust the base pointer again. This would require a label just before the beginning of the loop, before the cmpl instruction. The jump should occur if %eax is smaller the %ebx, so you would need a jge. Check out page 39 for why jge.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.
Since this is the end of the loop instructions, control should go to the beginning of the loop unconditionally.movl %eax, %ebx #makes %eax the maximum value ############# #Here I will also need to make all the loop again
I too am working through the book. Perhaps we can help each other out now and again.salir_maximo: movl %ebp, %esp popl %ebp retI'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!
Hope that helps, Justis
_______________________________________________ Pgubook-readers mailing list address@hidden http://lists.nongnu.org/mailman/listinfo/pgubook-readers
[Prev in Thread] | Current Thread | [Next in Thread] |