我的mips程序有问题。输入32位数字后,会显示一条消息,表示该数字是否为正方形。但是当您输入数字> 1000000时,程序不起作用。有人能帮帮我吗?
以mips编程:
.data
prompt: .asciiz "\nEnter an integer\n"
squareMessage: .asciiz " Is square "
nonsquareMessage: .asciiz " Isnt square "
isntMessage: .asciiz "Enter possitive number\n "
intMessage: .asciiz "Number is: "
.text
main:
loop:
#print prompt
la $a0 prompt
nop
nop
addi $v0 $zero 4
syscall
#read integer into $t0
addi $v0 $zero 5
syscall
move $t0 $v0
addi $t1 $zero 1
beq $t0, 1, vypis
nop
nop
#if cislo mensi nez 1
blt $t0, $t1, spatne
nop
nop
#if cislo vetsi nez 0
bgt $t0, $t1, ready
nop
nop
ready: #vypis zadaneho cisla
la $a0 intMessage
nop
nop
addi $v0 $zero 4
syscall
move $a0 $t0
addi $v0 $zero 1
syscall
li $t2, 1 # t2 is our counter (i)
j for
nop
nop
for: #for cyclus, zda je zadane cislo mocnina prizozeneho cisla
beq $t2, $t0, end # if we are done
nop
nop
mul $t3,$t2,$t2
beq $t3, $t0, vypis
nop
nop
#i++
addi $t2, $t2, 1 # add 1 to t2
j for
#nop
end: #vypis ze zadane cislo neni ctverec
la $a0 nonsquareMessage
addi $v0 $zero 4
j loop
syscall
vypis: #vypis ze zadane cislo je ctverec
la $a0 squareMessage
nop
nop
addi $v0 $zero 4
j loop
syscall
spatne:
# print enter possitive number
la $a0 isntMessage
nop
nop
addi $v0 $zero 4
j loop
syscall
loopEnd: jr $ra
C程序:
int main(){
int n, i, result;
printf("Enter number:\n");
scanf ("%d",&n);
if(n<=0){
printf("Enter possitive number");
}
else{
for(i = 1; i<= n;i++){
result = i * i;
if(result == n){
printf("Is square");
return 0;
}
}
printf("Isnt square");
}
return 0;
}