### Site Tools

base:exponentiation

# Differences

This shows you the differences between two versions of the page.

 base:exponentiation [2020-04-25 21:32]verz base:exponentiation [2020-06-04 19:36] (current)verz Both sides previous revision Previous revision 2020-06-04 19:36 verz 2020-04-25 21:32 verz 2020-04-25 21:22 verz created 2020-06-04 19:36 verz 2020-04-25 21:32 verz 2020-04-25 21:22 verz created Line 26: Line 26: ;       input:  B value to be raised ;       input:  B value to be raised ;               .A exponent ;               .A exponent - ; ; ; ; algo:  if .A=0 res=1 ; algo:  if .A=0 res=1 ;        if .A=1 res=B ;        if .A=1 res=B - ;                   _ + ;             _ - ;                  |  B*B if E=2 + ;            | B if E=1 - ;        Exp(B,E)= |  B*Exp(B,E-1) if E is odd + ;  Exp(B,E)= | B*Exp(B,E-1) if E is odd - ;                  |_ Exp(B,E/2)*Exp(B,E/2) if E is even + ;            |_Exp(B,E/2)*Exp(B,E/2) if E is even ; ; ; ************************************ ; ************************************ Line 46: Line 45: Exponent Exponent - cmp #0 + tax - beq res1 + beq res1        ; is E==0 ? + lda B + lsr + ora B+1 + beq resB        ; if B==0 or B==1 then result=B + txa cmp #1 cmp #1 bne ExpSub bne ExpSub - resB    lda #0          ; E=1, result=B + + resB    lda #0          ; E==1 | B==1 | B==0, result=B sta P+2 sta P+2 sta P+3 sta P+3 Line 58: Line 63: sta P+1 sta P+1 rts rts + res1    sta P+1         ; E=0, result=1 res1    sta P+1         ; E=0, result=1 sta P+2 sta P+2 Line 65: Line 71: rts rts - ExpSub  cmp #2 + ExpSub  lsr             ; E = int(E/2) - beq Sqr         ; E is 2 + beq resB        ; E is 1 - lsr             ; E = int(E/2) + bcs ExpOdd      ; E is Odd bcs ExpOdd      ; E is Odd + ExpEven jsr ExpSub      ; E is Even ExpEven jsr ExpSub      ; E is Even - ldx #\$FC + ldx #\$3 - _ldP    lda