MIPS Instruction programming

In summary, there was an error in compiling the MIPS instruction for computing the factorial of a given number. The output was a negative integer instead of a positive one. This could be due to a size or formatting issue, as the given factorial number was too large for 32-bit interpretation. The program for the MIPS instructions can be found in the provided link.
  • #1
rictor
7
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: 416
Engineering news on Phys.org
  • #2
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 rbelli1 and rictor
  • #3
20! truncated to 32 bits is -2102132736. It looks like you are calculating to 64 bits then displaying 32 bits.

BoB
 
  • Like
Likes rictor

1. What is MIPS instruction programming?

MIPS (Microprocessor without Interlocked Pipeline Stages) is a reduced instruction set computer (RISC) architecture that is commonly used in embedded systems and microprocessors. MIPS instruction programming refers to the process of writing programs or instructions that can be executed by a MIPS processor.

2. What are the advantages of using MIPS instruction programming?

MIPS instruction programming has several advantages, including a simpler and more efficient instruction set, better performance due to reduced instruction execution time, and easier debugging and porting of code. It is also a popular choice for embedded systems due to its low power consumption.

3. What are the basic components of a MIPS instruction?

A MIPS instruction consists of an opcode, which specifies the operation to be performed, and one or more operands, which provide the data for the operation. The operands can be immediate values, registers, or memory addresses.

4. How do I write a MIPS program?

To write a MIPS program, you will need a text editor to write the code and a MIPS assembler to convert the code into machine-readable instructions. The program will typically start with a main function and use a combination of instruction statements, such as load and store, arithmetic and logic operations, and control flow instructions.

5. What are some common instructions used in MIPS programming?

Some common instructions used in MIPS programming include add, sub, mul, and div for arithmetic operations, lw and sw for loading and storing data from/to memory, beq and bne for conditional branching, and jal and jr for function calls and returns.

Similar threads

  • Engineering and Comp Sci Homework Help
Replies
4
Views
3K
  • Engineering and Comp Sci Homework Help
Replies
2
Views
14K
  • Engineering and Comp Sci Homework Help
Replies
1
Views
2K
  • Engineering and Comp Sci Homework Help
Replies
9
Views
7K
Replies
11
Views
2K
  • Engineering and Comp Sci Homework Help
Replies
7
Views
2K
  • Engineering and Comp Sci Homework Help
Replies
1
Views
2K
  • Programming and Computer Science
Replies
6
Views
3K
Replies
6
Views
1K
  • General Engineering
Replies
1
Views
12K
Back
Top