在label.L0中,当我检查%eax register的值时,得到正确的值。但是当我检查ecx寄存器的值时,它给了我零。我不知道为什么。也许这就是我出现浮点分割错误的原因。有人能帮我找出原因吗。
我试图产生的逻辑是

while (sml > 0){
rem = lrg % sml;
lrg = sml;
sml = rem;
}

产生浮点错误的程序集文件是:
    .file "gcd.c"
    .section .rodata
.LC0:
    .string "%d"
.LC1:
    .string "%d\n"

    .text
    .globl main
    .type main, @function
main:
    pushl %ebp
    movl  %esp, %ebp
    andl  $-16, %esp
    subl  $32, %esp

    leal  -8(%ebp), %eax    #scan a value
    movl  %eax,  4(%esp)
    movl  $.LC0,  (%esp)
    call scanf

    leal  -12(%ebp), %eax   #scan a value
    movl  %eax,  4(%esp)
    movl  $.LC0,  (%esp)
    call scanf


.L2:
    movl $0, %eax
    cmpl -8(%ebp),%eax
    jle .L0
    jmp .L1

.L0:
    movl  -12(%ebp),%eax
    movl -8(%ebp),%ecx
    movl %eax,%edx
    sarl $31, %edx
    idivl %ecx
    movl %edx,%eax
    movl %eax, -16(%ebp)
    movl -8(%ebp),%edx
    movl %edx, -12(%ebp)
    movl -16(%ebp),%edx
    movl %edx, -8(%ebp)
    jmp .L2

.L1:
    movl -12(%ebp), %eax
    movl  %eax,  4(%esp)
    movl $.LC0, (%esp)
    call printf

    movl $0, %edx

    movl $0, %eax       #end of program
    leave
    ret

.LFE2:
    .size     main, .-main
    .ident     "GCC: (GNU) 4.2.3 (4.2.3-6mnb1)"
    .section    .note.GNU-stack,"",@progbits

最佳答案

我同意布雷特的看法。用jle替换jl

关于c - 将0分配给%ecx寄存器,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/13328851/

10-09 06:37