爱吃羊的猫猫

导航

【MIPS】解一元二次方程

编程环境:PCspim

 1 .text 
 2 .globl main 
 3  
 4 puzzle: 
 5 la $a0,output1 
 6 li $v0,4 
 7 syscall 
 8 jr $ra 
 9  
10 solution: 
11 move $t6,$zero 
12 radical: 
13 addi $t6,$t6,1 
14 mul $t7,$t6,$t6 
15 blt $t7,$t5,radical 
16  
17 deal: 
18 mul $t3,$t0,2 
19 sub $t4,$zero,$t1 
20 add $t5,$t4,$t6 
21 div $t5,$t3 
22 la $a0,output2 
23 li $v0,4 
24 syscall 
25 mflo $a0 
26 li $v0,1 
27 syscall 
28 sub $t5,$t4,$t6 
29 div $t5,$t3 
30 la $a0,output3 
31 li $v0,4 
32 syscall 
33 mflo $a0 
34 li $v0,1 
35 syscall 
36 jr $ra 
37  
38 solve: 
39 sub $t8,$zero,$t1 
40 mul $t9,$t0,2 
41 div $t8,$t9 
42 la $a0,output4 
43 li $v0,4 
44 syscall 
45 mflo $a0 
46 li $v0,1 
47 syscall 
48 jr $ra 
49  
50 main: 
51 la $a0,input1 
52 li $v0,4 
53 syscall 
54 li $v0,5 
55 syscall 
56 move $t0,$v0 
57 la $a0,input2 
58 li $v0,4 
59 syscall 
60 li $v0,5 
61 syscall 
62 move $t1,$v0 
63 la $a0,input3 
64 li $v0,4 
65 syscall 
66 li $v0,5 
67 syscall 
68 move $t2,$v0 
69 mul $t3,$t1,$t1 
70 mul $t4,$t0,4 
71 mul $t4,$t4,$t2 
72 sub $t5,$t3,$t4 
73 move $t9,$t5 
74 bgt $t5,$zero,solution 
75 beq $t5,$zero,solve 
76 blt $t5,$zero,puzzle 
77  
78 .data 
79 input1: .asciiz "Please input a:\n" 
80 input2: .asciiz "Please input b:\n" 
81 input3: .asciiz "Please input c:\n" 
82 output1: .asciiz "No result!\n" 
83 output2: .asciiz "The number x1 is:\n" 
84 output3: .asciiz "\nThe number x2 is:\n" 
85 output4: .asciiz "The only solve is:\n"

效果演示:(以 X²-4X+3=0,X²-2X+1=0,X²-X+1=0 为例)

 

posted on 2019-10-24 12:21  爱吃羊的猫猫  阅读(314)  评论(0编辑  收藏  举报