[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [Pgubook-readers] Chapter 3, Concepts, Stuck
From: |
杨峰 |
Subject: |
Re: [Pgubook-readers] Chapter 3, Concepts, Stuck |
Date: |
Wed, 11 Feb 2004 18:56:37 +0800 |
movl $data_items, %ecx
movl $date_end, %edx
we compare the address itself,not the content in the address.
> First of all, great first 3 chapters. I'm enjoying this.
>
> I'm stuck on "Modify the maximum program to use an ending address..."
>
> How would I get the ending address of data_items? If that's possible,
> how can I tell I've reached it? I have tried several approaches. Here is
> one, but it results in a Segmentation Fault:
>
>
> #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
>
>
>
> Basically using the current address of data_items we're working on to
> compare to what I think should be 1 word greater than the last of
> data_items. But I'm doing something wrong.
>
>
>
> _______________________________________________
> Pgubook-readers mailing list
> address@hidden
> http://mail.nongnu.org/mailman/listinfo/pgubook-readers