Last active
June 23, 2016 13:49
-
-
Save mik-laj/76a7339e605d083f28bdc0202680eaad to your computer and use it in GitHub Desktop.
Rekurencyjny Symbol Newtona dla Symulatora http://www.softwareforeducation.com/sms32v50/index.php Zródło: https://pl.wikipedia.org/wiki/Symbol_Newtona#Obliczanie_symbolu_Newtona
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
; function WspNewtonaRek( n, k : integer ) : integer; | |
; begin | |
; if (k = 0) or (k = n) then | |
; WspNewtonaRek := 1 | |
; else | |
; WspNewtonaRek := WspNewtonaRek( n-1, k-1 ) + WspNewtonaRek( n-1, k ); | |
; end; | |
; | |
; | |
; function newton(n, k){ | |
; if ((k != 0) && (k != n)){ | |
; return newton( n - 1, k) + newton(n - 1, k - 1); | |
; } | |
; return 1; | |
; } | |
; | |
; newton(9,7); | |
; Symbol Newtona rekurencyjny | |
; Input BL - n, CL - k | |
; Output AL | |
JMP start | |
ORG 5 | |
PUSH BL | |
PUSH CL | |
PUSH DL | |
CMP CL, 0 | |
JZ ret_1 | |
CMP CL, BL | |
JZ ret_1 | |
MOV DL, 0 ; r = 0; | |
DEC BL ; n -1 | |
CALL 5 ; newton(n - 1, k) | |
ADD DL, AL ; r += newton(n - 1, k) | |
DEC CL ; k - 1 | |
CALL 5 ; newton( n - 1, k - 1) | |
ADD DL, AL ; r += newton( n - 1, k - 1) | |
PUSH DL | |
POP AL | |
JMP ret | |
ret_1: | |
MOV AL, 1 | |
ret: | |
POP DL | |
POP CL | |
POP BL | |
RET | |
start: | |
MOV BL, 9 | |
MOV CL, 7 | |
CALL 5 | |
END |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment