【发布时间】:2015-11-13 11:52:53
【问题描述】:
下面是一个 x86 程序,用于从数字列表中查找最大数字。当到达结束地址时,我试图退出循环。 (在源码中标有data_ends:标签)。
# Program to find maximum number
# Program should end when an ending address is reached
.section .data
.globl data_items
data_items:
#These are the data items
.long 3,67,34,222,45,75,54,34,44,33,22,11,66
data_ends:
.section .text
.globl _start
_start:
movl $0, %edi
movl data_items(,%edi,4), %eax
movl %eax, %ebx
start_loop:
incl %edi
# Problem in below line
cmpl data_items(,%edi,4), data_ends
je loop_exit
movl data_items(,%edi,4), %eax
cmpl %ebx, %eax
jle start_loop
movl %eax, %ebx
jmp start_loop
loop_exit:
movl $1, %eax
int $0x80
但是从下面的as 输出可以看出,cmpl data_items(,%edi,4), data_ends 行有一些问题。
user $ as maxNum.s -o maxNum.o
maxNum.s: Assembler messages:
maxNum.s:28: Error: too many memory references for `cmp'
user $
看起来cmpl 指令的语法错误。我该如何解决这个问题?
【问题讨论】:
标签: x86 compare memory-address