2013-06-04 73 views
0

我希望程序能夠找到最大號碼,但想要以地址結尾。我是彙編新手,並使用AT & T語法。查找最大號碼的地址

.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 0 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 
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 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 return value, and it already has the number 
movl $1, %eax      #1 is the exit() syscall 
int $0x80 
+1

我已經採取了猜測,你說的x86彙編,並添加了這個標籤。如果這不正確,請重新標記適當的架構。世界上有多種類型的處理器,它們使用不同的彙編語言。 –

回答

0

只是痠痛EBX地址,而是與EBX比較,比較(%EBX)