Programming Forums
User Name Password Register
 

RSS Feed
FORUM INDEX | TODAY'S POSTS | UNANSWERED THREADS | ADVANCED SEARCH

Reply
 
Thread Tools Display Modes
Old Feb 24th, 2005, 9:38 PM   #1
mimic
Newbie
 
Join Date: Feb 2005
Posts: 2
Rep Power: 0 mimic is on a distinguished road
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
mimic is offline   Reply With Quote
Old Feb 24th, 2005, 9:50 PM   #2
tempest
Programming Guru
 
tempest's Avatar
 
Join Date: Oct 2004
Posts: 1,041
Rep Power: 5 tempest is on a distinguished road
Send a message via ICQ to tempest Send a message via AIM to tempest Send a message via Yahoo to tempest
        .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)"
__________________

tempest is offline   Reply With Quote
Old Feb 24th, 2005, 10:10 PM   #3
mimic
Newbie
 
Join Date: Feb 2005
Posts: 2
Rep Power: 0 mimic is on a distinguished road
a:=5+3;
b:=(print(a, a-1), 10*a);
print (b)






again pls.

Last edited by mimic; Feb 24th, 2005 at 11:39 PM.
mimic is offline   Reply With Quote
Old Feb 25th, 2005, 2:49 PM   #4
Ooble
I eat cake for breakfast.
 
Ooble's Avatar
 
Join Date: Jul 2004
Location: In my box.
Posts: 4,434
Rep Power: 8 Ooble is on a distinguished road
I swear this has gotta be homework.
__________________
Me :: You :: Them
Ooble is offline   Reply With Quote
Reply

Bookmarks

« Previous Thread in Forum | Next Thread in Forum »

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump




DaniWeb IT Discussion Community
All times are GMT -5. The time now is 4:47 PM.

Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC