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

私が取得しようとしているシリーズの明示的な定義は、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 ...}

4

0 に答える 0