![]() |
|
![]() |
|
|
Thread Tools | Display Modes |
|
|
#1 |
|
Newbie
Join Date: Feb 2005
Posts: 2
Rep Power: 0
![]() |
How to i convert this alphacode to assembly ??
function factorial(n)
{ define sum; if n <= 1 then return 1; sum = 1; for i=2 to n do sum = sum * i; return sum; } function binomial(n,k) { if n <= 0 or k => 0 or n <= k then return 1; return factorial(n)/(factorial(k)*factorial(n-k)); } print binomial(5,3) I think it's easy for you all help me pls...Best Regards, Mimic |
|
|
|
|
|
#2 |
|
Programming Guru
![]() |
.file "test.c"
.section .rodata
.LC0:
.string "%d\n"
.text
.globl main
.type main, @function
main:
pushl %ebp
movl %esp, %ebp
subl $8, %esp
andl $-16, %esp
movl $0, %eax
subl %eax, %esp
movl $3, 4(%esp)
movl $5, (%esp)
call binomial
movl %eax, 4(%esp)
movl $.LC0, (%esp)
call printf
movl $0, %eax
leave
ret
.size main, .-main
.globl factorial
.type factorial, @function
factorial:
pushl %ebp
movl %esp, %ebp
subl $12, %esp
cmpl $1, 8(%ebp)
jg .L3
movl $1, -12(%ebp)
jmp .L2
.L3:
movl $1, -4(%ebp)
movl $2, -8(%ebp)
.L4:
movl -8(%ebp), %eax
cmpl 8(%ebp), %eax
jle .L7
jmp .L5
.L7:
movl -4(%ebp), %eax
imull -8(%ebp), %eax
movl %eax, -4(%ebp)
leal -8(%ebp), %eax
incl (%eax)
jmp .L4
.L5:
movl -4(%ebp), %eax
movl %eax, -12(%ebp)
.L2:
movl -12(%ebp), %eax
leave
ret
.size factorial, .-factorial
.globl binomial
.type binomial, @function
binomial:
pushl %ebp
movl %esp, %ebp
pushl %esi
pushl %ebx
subl $16, %esp
cmpl $0, 8(%ebp)
jle .L10
cmpl $0, 12(%ebp)
jns .L10
movl 8(%ebp), %eax
cmpl 12(%ebp), %eax
jle .L10
jmp .L9
.L10:
movl $1, -12(%ebp)
jmp .L8
.L9:
movl 8(%ebp), %eax
movl %eax, (%esp)
call factorial
movl %eax, %ebx
movl 12(%ebp), %eax
movl %eax, (%esp)
call factorial
movl %eax, %esi
movl 12(%ebp), %edx
movl 8(%ebp), %eax
subl %edx, %eax
movl %eax, (%esp)
call factorial
imull %esi, %eax
movl %eax, -16(%ebp)
movl %ebx, %eax
cltd
idivl -16(%ebp)
movl %eax, -16(%ebp)
movl -16(%ebp), %eax
movl %eax, -12(%ebp)
.L8:
movl -12(%ebp), %eax
addl $16, %esp
popl %ebx
popl %esi
popl %ebp
ret
.size binomial, .-binomial
.section .note.GNU-stack,"",@progbits
.ident "GCC: (GNU) 3.3.5 (Debian 1:3.3.5-3)"
__________________
|
|
|
|
|
|
#3 |
|
Newbie
Join Date: Feb 2005
Posts: 2
Rep Power: 0
![]() |
a:=5+3;
b:=(print(a, a-1), 10*a); print (b) again pls. Last edited by mimic; Feb 25th, 2005 at 12:39 AM. |
|
|
|
![]() |
| Bookmarks |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
| Display Modes | |
|
|