问题描述
我在,我们必须写两个函数赋值。还必须检测使用处理器的条件codeS溢出情况,并返回 0
来表示已遇到一个错误。我能写的功能。
I have an assignment in which we have to write two functions. Also must detect overflow conditions using the processor's condition codes and return 0
to indicate that an error has been encountered. I was able to write the functions.
.file "formula.c"
.text
.globl _nCr
.def _nCr; .scl 2; .type 32; .endef
_nCr:
pushl %ebp
movl %esp, %ebp
subl $56, %esp
movl 8(%ebp), %eax
movl %eax, (%esp)
testl %eax, %eax
call _factorial
movl %eax, -12(%ebp)
movl 12(%ebp), %eax
addl $1, %eax
movl %eax, (%esp)
call _factorial
movl %eax, -16(%ebp)
movl 12(%ebp), %eax
notl %eax
addl 8(%ebp), %eax
movl %eax, (%esp)
call _factorial
movl %eax, -20(%ebp)
movl -16(%ebp), %eax
movl %eax, %edx
imull -20(%ebp), %edx
movl %edx, -28(%ebp)
movl -12(%ebp), %eax
movl %eax, %edx
sarl $31, %edx
idivl -28(%ebp)
leave
ret
.globl _factorial
.def _factorial; .scl 2; .type 32; .endef
_factorial:
pushl %ebp
movl %esp, %ebp
subl $16, %esp
movl $1, -8(%ebp)
movl $1, -4(%ebp)
jmp L3
L4:
movl -8(%ebp), %eax
imull -4(%ebp), %eax
movl %eax, -8(%ebp)
addl $1, -4(%ebp)
L3:
movl -4(%ebp), %eax
cmpl 8(%ebp), %eax
jle L4
movl -8(%ebp), %eax
leave
ret
.def ___main; .scl 2; .type 32; .endef
.section .rdata,"dr"
.align 4
这个功能基本上没有 N!/ R!(N-R)!
。如果数量较大的溢出发生在阶乘。我只是不明白我怎么会设置溢出条件。
This function basically does n!/r!(n-r)!
. The overflow occurs in factorial when the numbers get larger. I just do not understand how I would set the overflow conditions.
推荐答案
1)您的算术命令是可能设置溢出位的操作
1) Your arithmetic commands are the operations that could potentially set the overflow bit
2)JO溢出(跳)和JNO上不溢出(跳)允许您分支,根据是否产生溢出与否
2) The "JO" (jump on overflow) and "JNO" (jump on not overflow) allow you to branch, depending on whether an overflow occurred or not
3)你很可能只是联办后,将%EAX为0。
3) You'd probably just set "%eax" to 0 after "JO".
4)优秀的,如果你不熟悉它优秀的资源:
4) Excellent, excellent resource if you're not already familiar with it:
这篇关于如何检测在大会语言特点X86溢出条件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!