Created
June 23, 2016 13:47
-
-
Save mik-laj/6a9cf44d436c16f7c96a821c98ccd8b7 to your computer and use it in GitHub Desktop.
# Obliczenia Symbolu Newtona
This file contains 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