Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/ssis/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Assembly 返回意外值的简单x86 linux汇编程序_Assembly - Fatal编程技术网

Assembly 返回意外值的简单x86 linux汇编程序

Assembly 返回意外值的简单x86 linux汇编程序,assembly,Assembly,下面是一个简单的程序,可以找到最少的数据项。0用于终止内存块。%ebx正在跟踪当前最小值,由于je指令,0不应被复制到其中。然而,这个程序将0返回到操作系统,而不是3。 编辑:此处的正确代码: 这种逻辑是不对的 在C代码中,您的程序看起来像 edi = 0; eax = data_items[edi]; ebx = eax; while(eax != 0) { eax = data_items[++edi]; if(eax < ebx) ebx = eax; } exi

下面是一个简单的程序,可以找到最少的数据项。0用于终止内存块。%ebx正在跟踪当前最小值,由于
je
指令,0不应被复制到其中。然而,这个程序将0返回到操作系统,而不是3。

编辑:此处的正确代码:

这种逻辑是不对的

在C代码中,您的程序看起来像

edi = 0;
eax = data_items[edi];
ebx = eax;
while(eax != 0) {
    eax = data_items[++edi];
    if(eax < ebx) ebx = eax;
}
exit(ebx);
edi=0;
eax=数据项[edi];
ebx=eax;
while(eax!=0){
eax=数据项[++edi];
如果(eax

问题是您加载
eax
,然后立即将其存储为最小值。如果
eax=0
,则将其存储为最小值(因为它是最小值),然后才断开。

由于不得不不时使用蹩脚的反汇编程序,我被困在at&t语法的某个地方,我学会了阅读at&t语法。显然,我仍然非常喜欢Intel语法…谢谢,我将循环中的0检查移到了eax设置之后。
.section .data

data_items:
 .long 3,67,34,222,45,75,54,34,44,222,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        #first item, so its biggest, ebx tracks biggest

 start_loop:
  incl %edi
  movl data_items(,%edi,4), %eax
  cmpl $0, %eax
  je loop_exit

  cmpl %ebx, %eax
  jge start_loop

  movl %eax, %ebx
  jmp start_loop

 loop_exit:
  movl $1, %eax
  int $0x80
edi = 0;
eax = data_items[edi];
ebx = eax;
while(eax != 0) {
    eax = data_items[++edi];
    if(eax < ebx) ebx = eax;
}
exit(ebx);