为什么LOOP指令导致"-288的值对于1个字节的字段而言太大"? [英] Why does the LOOP instruction result in "value of -288 too large for field of 1 bytes"

查看:118
本文介绍了为什么LOOP指令导致"-288的值对于1个字节的字段而言太大"?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我尝试运行使用loop命令的汇编代码时出现此错误:

I'm getting this error when I try to run my assembly code that uses a loop command:

"rip.s:190:错误:-288的值对于497处1个字节的字段太大."

"rip.s:190: Error: value of -288 too large for field of 1 bytes at 497".

应在程序循环时立即发生此错误.我最初尝试在%ecx寄存器中将"3"放入循环之前,但仍然遇到相同的错误.我不确定为什么会这样,所以我真的不知道如何解决它.我已经在下面附上了相关代码:

This error occurs right when the program is supposed to loop. I tried initially putting "3" in the %ecx register before it enters the loop but I still get the same error. I'm not sure why this is happening so I don't really know how to go about fixing it. I've attached the pertinent code below:

    //Other code
    movl    %ecx, -20(%ebp)
    movl    $0, %ecx
    addl    $3, %ecx
    .L24:
    xorl    %edi, %edi
    movl    -32(%ebp), %ebx
    movl    -44(%ebp), %esi
    cmpl    %esi, -52(%ebp)
    movl    %ebx, -48(%ebp)
    jg  .L11
    movl    -52(%ebp), %eax
    movl    %ebx, %edx
    xorl    %edi, %edi
    subl    $2, %edx
    movl    %edx, -40(%ebp)
    movl    %eax, -36(%ebp)
    .p2align 4,,7
    .p2align 3
    .L19:
    movl    -36(%ebp), %eax
    testl   %eax, %eax
    js  .L42
    movl    16(%ebp), %ebx
    cmpl    %ebx, -36(%ebp)
    je  .L11
    .L13:
    movl    -40(%ebp), %ebx
    cmpl    %ebx, -32(%ebp)
    jl  .L14
    movl    -36(%ebp), %esi
    addl    16(%ebp), %esi
    movl    %edi, -60(%ebp)
    movl    %esi, -28(%ebp)
    jmp .L31
    .p2align 4,,7
    .p2align 3
    .L15:
    movl    %edx, -24(%ebp)
    movl    -20(%ebp), %edx
    cmpl    %edx, %ebx
    movl    %edx, -20(%ebx)
    movl    -24(%ebp), %edx
    je  .L38
    .L16:
    movl    -28(%ebp), %edx
    movl    8(%ebp), %edi
    movl    %edx, %eax
    sarl    $31, %edx
    idivl   16(%ebp)
    movl    %edx, %esi
    movl    %eax, -24(%ebp)
    movl    -20(%ebp), %eax
    leal    (%ebx,%eax), %edx
    movl    %eax, -20(%ebp)
    movl    %edx, %eax
    sarl    $31, %edx
    idivl   -20(%ebp)
    movl    (%edi,%esi,4), %eax
    cmpl    $1, (%eax,%edx,4)
    sbbl    $-1, -60(%ebp)
    addl    $1, %ebx
    cmpl    -32(%ebp), %ebx
    jg  .L38
    .L31:
    testl   %ebx, %ebx
    jns .L15
    addl    $1, %ebx
    jmp .L16
    .p2align 4,,7
    .p2align 3
    .L38:
    movl    -60(%ebp), %edi
    .L14:
    addl    $1, -36(%ebp)
    movl    -44(%ebp), %eax
    cmpl    %eax, -36(%ebp)
    jle .L19
    .L11:
    movl    -44(%ebp), %ebx
    movl    8(%ebp), %esi
    movl    -32(%ebp), %edx
    movl    -4(%esi,%ebx,4), %eax
    addl    $1073741823, %edx
    movl    -56(%ebp), %esi
    movl    (%eax,%edx,4), %eax
    movl    -4(%esi,%ebx,4), %ebx
    cmpl    $1, %eax
    adcl    $-1, %edi
    cmpl    $3, %edi
    movl    %eax, -28(%ebp)
    movl    $1, %eax
    je  .L22
    xorb    %al, %al
    cmpl    $2, %edi
    je  .L43
    .L22:
    addl    $1, -32(%ebp)
    movl    %ebx, -24(%ebp)
    movl    -20(%ebp), %ebx
    cmpl    -48(%ebp), %ebx
    movl    %ebx, -20(%ebp)
    movl    -24(%ebp), %ebx
    movl    %eax, (%ebx,%edx,4)
    loop .L24 <--Error occurs right here
    .L9:
    addl    $1, -44(%ebp)
    jmp .L8

是什么原因导致错误?

推荐答案

那是编译(组装)时间错误,而不是运行时错误. loop指令的跳转目标只有8位有符号偏移,汇编程序试图告诉您目标超出范围.

That's a compile (assembly) time error, not a runtime one. The loop instruction only has a 8 bit signed offset for the jump target, the assembler is trying to tell you that your target is out of range.

您应在循环的底部(

You should replace the loop instruction with the equivalent dec ecx; jnz .L24 at the bottom of your loop (which is recommended anyway for optimization purposes). The only difference is that dec overwrites EFLAGS.

x86循环不必使用loop 指令;当方便使用ECX作为计数器时,这是对代码大小的窥视孔优化. (并且以牺牲Intel CPU的速度为代价.)

x86 loops don't have to use the loop instruction; it's a peephole optimization for code-size when it's convenient to use ECX as a down-counter. (And comes at the expense of speed on Intel CPUs.)

这篇关于为什么LOOP指令导致"-288的值对于1个字节的字段而言太大"?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆