user2316721
user2316721

Reputation: 19

MIPS homework, factorial for large number

I have to write program that calculates factorial for large numbers (e.g 200). This is very important for me. Here is my code:

  .text
    main:
    li $v0, 4
    la $a0, prompt
    syscall

    li $v0, 5
    syscall
    move $s0, $v0
    move $t1, $v0
    li $t0, 1
    loop:
    mul $t0, $t0, $s0

    addi $s0, $s0, -1
    bgtz $s0, loop

    li $v0, 1
    move $a0, $t0
    syscall

    li $v0, 10
    syscall

    .data
    prompt: .asciiz "\nGive a number: "

This program works only for numbers less than 31. I don't know how to fix it. Someone can help me?

P.S Sorry for my bad language.

Upvotes: 0

Views: 2947

Answers (1)

markgz
markgz

Reputation: 6266

The point of this homework assignment is for the student to implement arbitrary precision integer addition and multiplication in MIPS, and then use it to implement the factorial algorithm. Here is an example for arbitrary precision factorial in pseudo-code.

Upvotes: 1

Related Questions