1
在標籤.L0,當我檢查%EAX寄存器的值,我得到正確的值。但是當我檢查ecx寄存器的值時,它給我零。我不知道爲什麼。也許這就是我得到浮點分割錯誤的原因。有人可以幫我找出原因。分配的0到%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
如果'-8(%ebp)'等於'(0)',就會採用'jle'。這個值然後用作除數。 –
爲什麼不發佈生成該彙編列表的'gcd.c' C代碼? –