MIPS Input/Output: Translate & Test Program

  • Thread starter heyhey
  • Start date
  • Tags
    Mips
In summary, this code is attempting to translate a program using the SPIM compiler. It includes a main function with a for loop, a PerfectSquare function, and a prompt message and error message. However, the code is not working on the SPIM compiler and it is unclear what the issue is.
  • #1
heyhey
1
0
This is the program I need to translate:
Code:
main()
{
    int i;
    int number=0;
    int result=0;

    for(i=0; i<10; i++){
        printf("Testing:");
        scanf("%i",&number);


        result = PerfectSquare(number);

        if(result==0)
            printf("Fail\n");
        else
            printf("%i\n",result);

    }

And this is my attempt...But it's not working on the SPIM compiler.

Code:
.data							
promptmsg:.asciiz "Testing:"	
msg1:.asciiz "Fail!"	
.text
.globl main


main:				#start of code

li 	$v0,4			#store 4 in $v0
la 	$a0,promptmsg		#copy RAM address of promptmsg into $a0 
	syscall 		#print msg
li 	$v0,5			#store 5 in $v0
li 	$t0,10			#t0 is a constant 0
li 	$t1,0			#t1 is the counter(i) for loop
loop:
beq 	$t1,$t0,end		#if t1==10 we are done
	syscall			#call operating system to perform operation
add 	$a0,$v0,$0 		#move $v0 to $a0

jal 	PerfectSquare		#call PerfectSquare function
add 	$a0,$v0,$0		#move to $a0

li 	$v0,1			#store 1 in $v0
la 	$a0,msg1		#copy RAM address of promptmsg into $a0
	syscall			# call operating system to perform operation

li 	$v0,10			#store 10 in $v0
	syscall			# call operating system to perform operation
end:
 
Technology news on Phys.org
  • #2
heyhey said:
This is the program I need to translate:
Code:
main()
{
    int i;
    int number=0;
    int result=0;

    for(i=0; i<10; i++){
        printf("Testing:");
        scanf("%i",&number);


        result = PerfectSquare(number);

        if(result==0)
            printf("Fail\n");
        else
            printf("%i\n",result);

    }
Where is the code for the PerfectSquare function?
heyhey said:
And this is my attempt...But it's not working on the SPIM compiler.
"Not working" is pretty vague. Are you getting assembler errors? If not, what output are you getting?
heyhey said:
Code:
.data							
promptmsg:.asciiz "Testing:"	
msg1:.asciiz "Fail!"	
.text
.globl main


main:				#start of code

li 	$v0,4			#store 4 in $v0
la 	$a0,promptmsg		#copy RAM address of promptmsg into $a0 
	syscall 		#print msg
li 	$v0,5			#store 5 in $v0
li 	$t0,10			#t0 is a constant 0
li 	$t1,0			#t1 is the counter(i) for loop
loop:
beq 	$t1,$t0,end		#if t1==10 we are done
	syscall			#call operating system to perform operation
add 	$a0,$v0,$0 		#move $v0 to $a0

jal 	PerfectSquare		#call PerfectSquare function
add 	$a0,$v0,$0		#move to $a0

li 	$v0,1			#store 1 in $v0
la 	$a0,msg1		#copy RAM address of promptmsg into $a0
	syscall			# call operating system to perform operation

li 	$v0,10			#store 10 in $v0
	syscall			# call operating system to perform operation
end:
 

What is MIPS Input/Output?

MIPS Input/Output (I/O) is a set of instructions used in the MIPS assembly language to input and output data from a computer system. It allows for communication between the computer and external devices such as keyboards, printers, and displays.

How do you translate a program using MIPS I/O instructions?

To translate a program using MIPS I/O instructions, you will need to use a MIPS compiler, such as SPIM or MARS. The program should be written in MIPS assembly language, and the compiler will then convert it into machine code that can be run on a MIPS processor.

What is the purpose of testing a MIPS I/O program?

The purpose of testing a MIPS I/O program is to ensure that it functions correctly and produces the desired output. This involves running the program with different inputs and verifying that the outputs are correct. Testing helps to identify and fix any errors or bugs in the program before it is used in a production environment.

What are some common mistakes to avoid when using MIPS I/O instructions?

Some common mistakes to avoid when using MIPS I/O instructions include not properly initializing registers, not checking for errors in input or output operations, and not properly closing input or output streams. It is also important to make sure that the program is using the correct I/O instructions for the specific task.

How can I improve the performance of a MIPS I/O program?

To improve the performance of a MIPS I/O program, you can minimize the number of I/O operations, use efficient I/O instructions, and properly manage input and output streams. It is also important to optimize the data structures and algorithms used in the program to reduce the number of instructions needed for I/O operations.

Similar threads

  • Programming and Computer Science
Replies
4
Views
1K
  • Engineering and Comp Sci Homework Help
Replies
4
Views
3K
  • Engineering and Comp Sci Homework Help
Replies
2
Views
4K
  • Programming and Computer Science
Replies
1
Views
2K
  • Programming and Computer Science
Replies
1
Views
7K
  • Engineering and Comp Sci Homework Help
Replies
22
Views
4K
  • Programming and Computer Science
Replies
1
Views
7K
  • Programming and Computer Science
Replies
5
Views
9K
  • Programming and Computer Science
Replies
20
Views
31K
  • Programming and Computer Science
Replies
4
Views
7K
Back
Top