pgubook-readers
[Top][All Lists]
Advanced

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

Re: [Pgubook-readers] Chapter 3, Concepts, Stuck


From: Jonathan Bartlett
Subject: Re: [Pgubook-readers] Chapter 3, Concepts, Stuck
Date: Wed, 11 Feb 2004 09:52:07 -0800 (PST)

Almost perfect!  The two lines:

movl data_items, %ecx
movl data_end, %edx

are slightly wrong.  These load the value located in these two addresses
to the registers, no the addresses themselves.  To load the addresses as
values, you need to specify immediate-mode with the dollar sign:

movl $data_items, %ecx
movl $data_end, %edx

Also, your ".long 0" after data_end is unnecessary, I believe.  It will
refer to the next address even if nothing is specified.

Finally, you can also now just use %ecx to do the moves instead of using
%edi, since %ecx will have the address you are loading from anyway.

Change:

movl data_items(,%edi,4)

to

movl (%ecx)

And you can just stop using %edi altogether.

Looks like you're doing good!

Jon


On 11 Feb 2004, Tim Hilton wrote:

> #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
>
>
>
> _______________________________________________
> Pgubook-readers mailing list
> address@hidden
> http://mail.nongnu.org/mailman/listinfo/pgubook-readers
>





reply via email to

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