Hi Stefan,

It's hard to tell without seeing how you coded the function that compare 
values inside "data_items".

But try out the following:

data_items:
        .int 34,67,34,222,45,75,38,19,29,39,100,0

.section .text
.globl _start
_start:
        mov $0, %edi
       /* Load the first byte */
        mov data_items(,%edi,4), %eax
        movl %eax, %ebx
        call GetMax

[....]

.type GetMax, @function
GetMax:
        /* Return after hitting the end(e.g. 0) */
        cmp $0, %eax
        je Return

        /* else increment the pointer and load next value */
        inc %edi
        mov data_items(,%edi,4), %eax

/* Restart looping if the current number is <= to the biggest 
recorded so far */
        cmp %ebx, %eax
        jle GetMax

/* else, record the new max value and restart looping */
        mov %eax, %ebx
        jmp GetMax
        ret


--
Makhtar


On Tuesday 25 November 2008 17:01:56 you wrote:

> Today's Topics:
>
>    1. problem with maximum (Stefan Ciobaca)

> Message: 1
> Date: Sat, 22 Nov 2008 22:48:17 +0100
> From: "Stefan Ciobaca" <[EMAIL PROTECTED]>
> Subject: [Pgubook-readers] problem with maximum
> To: [email protected]
> Message-ID:
>       <[EMAIL PROTECTED]>
> Content-Type: text/plain; charset=ISO-8859-1
>
> Hi!
>
> I have just started to read the book but I have a problem with the first
> real program in the book (that computes the maximum value from an
> array) -- it always outputs 0.
>
> In fact, I have isolated the problem to a couple of instructions. Here is
> my code
>
> .section .data
>
> data_items:
>       .long 34,67,34,222,45,75,38,19,29,39,100,0
>
> .section .text
>
> .globl _start
> _start:
>       movl data_items, %eax
>       movl %eax, %ebx
>       movl $1, %eax
>       int $0x80
>
> This code exits with error code 0.
>
> However, if instead of
>       movl data_items, %eax
>       movl %eax, %ebx
> I do
>       movl data_items, %ebx
>
> it exits with the expected error code 34.
>
> Does anyone have any idea what's wrong?
>
> Stefan Ciobaca

_______________________________________________
Pgubook-readers mailing list
[email protected]
http://lists.nongnu.org/mailman/listinfo/pgubook-readers

Reply via email to