| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 1076 人关注过本帖
标题:照书上打的,不知道为什么会出现段错误???
取消只看楼主 加入收藏
xxwpk007
Rank: 4
等 级:业余侠客
帖 子:166
专家分:289
注 册:2007-7-29
结帖率:100%
收藏
 问题点数:0 回复次数:1 
照书上打的,不知道为什么会出现段错误???
程序代码:
#PURPOSE: This program finds the maximunj number of a
# set of data items.
#
#VARIABLES: The registers have the following uses:
#
# %edi - Holds the index of the data item being examined
# %ebx - Largest data item found
# %eax - Current data item
#
# The following memory locations are used:
#
# data_items - contains the item data. A 0 is used
# to terminate the data
#
.section .data
data_items:           #These are the data items
.long 3,67,34,222,45,75,54,34,44,33,22,11,66,0

.section .text
.globl _start
_start:
movl $0, %edi        # move o into the index register
movl data_items(,%edi,4), %eax  # load the first byte of data
movl %eax, %ebx     # since this is the first item,%eax is the biggest

start_loop:           # start loop
cmpl $0,%eax        # check to see if we've hit the end
incl %edi        
je loop_exit
incl %edi          # load next value
movl data_items(,%edi,4), %eax
cmpl %ebx,%eax     # compare values
jle start_loop     # jump to loop beginning if the new
                   # one isn,t bigger
movl %eax,%ebx     #move the value as the largest
jmp start_loop    # jump to loop beginning

loop_exit:
# %ebx is the status code for the _exit system call
# and it already has the maximum number
movl $1,%eax       #1 is the _exit() syscall
int $0x80


[ 本帖最后由 xxwpk007 于 2010-1-27 20:49 编辑 ]
搜索更多相关主题的帖子: edi following registers memory 
2010-01-27 20:36
xxwpk007
Rank: 4
等 级:业余侠客
帖 子:166
专家分:289
注 册:2007-7-29
收藏
得分:0 

找到错误了,
cmpl $0,%eax        # check to see if we've hit the end
incl %edi        #这里打错了。
je loop_exit
incl %edi          # load next value
2010-01-27 20:50
快速回复:照书上打的,不知道为什么会出现段错误???
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.030355 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved