pgubook-readers
[Top][All Lists]
Advanced

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

[Pgubook-readers] Re: problem with maximum (Stefan Ciobaca)


From: Makhtar Diouf
Subject: [Pgubook-readers] Re: problem with maximum (Stefan Ciobaca)
Date: Tue, 25 Nov 2008 17:46:56 +0000
User-agent: KMail/1.10.3 (Linux/2.6.26-ucloneh; KDE/4.1.3; x86_64; ; )

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" <address@hidden>

> Subject: [Pgubook-readers] problem with maximum

> To: address@hidden

> Message-ID:

> <address@hidden>

> 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


reply via email to

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