0
;==============================================================================================
    ; 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
;============================================================================

The explicit definition of the serries I'm trying to get is 1*2 + 2*3 + 3*4 ... + i(i+1).

I've got the math for it down and I found that the recursive definition for the series is a_n = a_(n-1) + 2(n-1) with a_1 = 0 as a base case. I'm trying to figure out why this code keeps giving me the even series: {2,4,6,8,10 ...} instead of the series I'm trying to calculate

0 Answers0