-
Notifications
You must be signed in to change notification settings - Fork 0
/
quad.asm
96 lines (66 loc) · 1.42 KB
/
quad.asm
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
.data
inputA: .asciiz "Enter A: \n"
inputB: .asciiz "Enter B: \n"
inputC: .asciiz "Enter C: \n"
solution: .asciiz "Solutions: \n"
noSolution: .asciiz "There are no solutions! \n"
.text
main:
#prompting for inputs A, B, and C, and then parsing them into variables.
#for A
li $v0, 4
la $a0, inputA
syscall
li $v0, 5 #getting input value
syscall
add $t0, $zero, $v0 #parse A into $t0
#for B
li $v0, 4
la $a0, inputB
syscall
li $v0, 5
syscall
add $t1, $zero, $v0 #parse B into $t1
#for C
li $v0, 4
la $a0, inputC
syscall
li $v0, 5
syscall
add $t2, $zero, $v0 #parse C into $t2
la $a0, solution
li $v0, 4
syscall
rem $t3, $t0, $t1 # $t3 = a mod b
addi $t4, $zero, 0 #initializing iterators to 0
addi $t5, $zero, 0
loop:
bgt $t4, $t2, fin #if i > c we're done
mult $t4, $t4 #calculating i^2
mflo $t6 # $t6 = i^2
rem $t7, $t6, $t1 # $t7 = i^2 mod b
beq $t7, $t3, printAndIterate # if R = R, print new x
addi $t4, $t4, 1 # continue, otherwise
j loop
printAndIterate:
#print i
move $a0, $t4
li $v0, 1
syscall
#print space
la $a0, 32
li $v0, 11
syscall
addi $t5, $t5, 1 #iterate checker
addi $t4, $t4, 1 # i++
j loop #return to start of process
#Print if no solutions
noSolPrint:
li $v0, 4
la $a0, noSolution
syscall
addi $t5, $t5, 1 #iterate the checker to ensure done
fin:
beq $t5, 0, noSolPrint #check if no solution
li $v0, 10
syscall