Pascal's triangle: Difference between revisions

no edit summary
No edit summary
Line 5,207:
1 18 153 816 3060 8568 18564 31824 43758 48620 43758 31824 18564 8568 3060 816 153 18 1
1 19 171 969 3876 11628 27132 50388 75582 92378 92378 75582 50388 27132 11628 3876 969 171 19 1</pre>
 
=={{header|X86 Assembly}}==
{{works with|NASM}}
{{works with|Windows}}
<b>uses:</b> io.inc - Macro library from SASM
<lang asm>
%include "io.inc"
 
section .text
global CMAIN
CMAIN:
mov ebp, esp; for correct debugging
mov ebx, 7 ;size
call mloop
ret
mloop:
mov edx, 0 ;edx stands for the nth line
looping:
push ebx
push edx
call line
pop edx
pop ebx
inc edx
cmp edx, ebx
jl looping
xor eax, eax
ret
line:
mov ecx, 0 ;ecx stands for the nth character in each line
mlp:
push ecx
push edx
call nCk
pop edx
pop ecx
PRINT_DEC 4, eax ;print returned number
PRINT_STRING " "
inc ecx
cmp ecx, edx ;if
jle mlp
NEWLINE
ret
nCk:
;ecx : j
;edx : i
mov esi, edx
call fac ;i!
push eax ;save i!
mov esi, ecx
call fac ;j!
push eax ;save j!
mov ebx, edx
sub ebx, ecx ;(i-j)
mov esi, ebx
call fac ;(i-j)!
pop ebx ;(i-j)! is in eax
mul ebx ;(i-j)! * j!
mov ecx, eax
pop eax ; get i!
div ecx ; ; last step : i! divided by (i-j)! * j!
ret
fac:
push ecx
push edx
mov eax, 1
mov ecx, esi
cmp ecx, 0 ; 0! returns 1
je facz
lp:
mul ecx ;multiplies eax by ecx and then decrements ecx until ecx is 0
dec ecx
cmp ecx, 0
jg lp
jmp end
facz:
mov eax, 1
end:
pop edx
pop ecx
ret
</lang>
{{out}}
<pre>
1
1 1
1 2 1
1 3 3 1
1 4 6 4 1
1 5 10 10 5 1
1 6 15 20 15 6 1
</pre>
 
=={{header|XBasic}}==
13

edits