- #1
heyhey
- 1
- 0
This is the program I need to translate:
And this is my attempt...But it's not working on the SPIM compiler.
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: