MIPS Input/Output: Translate & Test Program

  • Thread starter Thread starter heyhey
  • Start date Start date
  • Tags Tags
    Mips
Join the discussion
Ask a follow-up here, or get your own question answered by working scientists, mathematicians and engineers — people, not an autocomplete.
Real named experts · corrections over time · the nuance an AI answer skips
1 reply · 7K views
heyhey
Messages
1
Reaction score
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:
 
on Phys.org
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: