Why Does MIPS Show a Negative Result for Large Factorials?

rictor
Messages
7
Reaction score
0
when I try to compile the MIPS instruction in order to compute the factorial of n number? i get the following error in the console as:
Enter the factorial number: 20
factorial of given number: -2102132736
The output which I am getting as negative integer of a given factorial instead of positive integer.
The program for the given MIPS instructions is seen in the link below:
https://gist.github.com/dcalacci/3747521
 

Attachments

  • upload_2016-11-10_1-7-44.png
    upload_2016-11-10_1-7-44.png
    1.5 KB · Views: 528
Engineering news on Phys.org
Looks like a size or a formatting problem:
2102132736 is 31 bits and -2102132736 is 32 bits interpreted as a 4 byte integer (first bit a sign bit)

For 20! you need more than 62 bits
 
  • Like
Likes   Reactions: rbelli1 and rictor
20! truncated to 32 bits is -2102132736. It looks like you are calculating to 64 bits then displaying 32 bits.

BoB
 
  • Like
Likes   Reactions: rictor

Similar threads

  • · Replies 4 ·
Replies
4
Views
5K
Replies
11
Views
2K
  • · Replies 1 ·
Replies
1
Views
13K
  • · Replies 1 ·
Replies
1
Views
3K
  • · Replies 1 ·
Replies
1
Views
5K
  • · Replies 6 ·
Replies
6
Views
2K
  • · Replies 7 ·
Replies
7
Views
3K
  • · Replies 4 ·
Replies
4
Views
3K
Replies
6
Views
4K
  • · Replies 1 ·
Replies
1
Views
3K