;==============================================================================================
; recursive procedure:
; supersum(int x)
; returns 1*2 + 2*3 + 3*4 + ... + i*(i+1)
supersum PROC
push ebp ; start of every procedure
mov ebp, esp
push ebx
; Actual subproc calc here
mov eax, [ebp +8] ; returning eax to the original called value
cmp eax,1
je basecase
dec eax ; (n-1) ; its just a lie...
mov recnum, eax ; saving dec val for call
mul double ; 2(n-1)
mov rhs, eax ; the right hand side is finished
push recnum
call sumseries ; a_(n-1)
add esp, 4
definition:
add eax, rhs ; a_(n-1)+ 2(n-1)
jmp skp
basecase: ; a_1 = 0
mov eax, 0
mov rhs, 2
jmp definition
skp:
pop ebx
pop ebp
ret
supersum ENDP
;============================================================================
我想要获得的serries的明确定义是1 * 2 + 2 * 3 + 3 * 4 ... + i(i + 1)。
我已经得到了它的数学,我发现该系列的递归定义是a_n = a_(n-1)+ 2(n-1),其中a_1 = 0作为基本情况。我想弄清楚为什么这段代码会给我一个偶数系列:{2,4,6,8,10 ...}而不是我想要计算的系列