File tree Expand file tree Collapse file tree 1 file changed +68
-0
lines changed Expand file tree Collapse file tree 1 file changed +68
-0
lines changed Original file line number Diff line number Diff line change
1
+ ##Writer: Minhas Kamal
2
+ ##Date: 01 -MAY-2014
3
+ ##Function: Finds prime numbers in a certain range.
4
+
5
+ #####**data**#####
6
+ .data
7
+
8
+ prompt: .asciiz "Enter your range: "
9
+ new_line: .asciiz "\n"
10
+
11
+ #####**text**#####
12
+ .text
13
+
14
+ main:
15
+ la $a0 , prompt #prompt for user input
16
+ li $v0, 4
17
+ syscall
18
+
19
+ li $v0, 5 #take start integer
20
+ syscall
21
+ add $t1, $v0, $zero
22
+
23
+ li $t0, 2 #see if divisible by 2 or not (even or odd)
24
+ div $t4, $t1, $t0
25
+ mul $t4, $t4, $t0
26
+ bne $t4, $t1, odd
27
+ addi $t1, $t1, 1 #if even make odd
28
+ odd:
29
+
30
+ li $v0, 5 #take stop integer
31
+ syscall
32
+ add $t2, $v0, $zero
33
+
34
+
35
+ addi $t3, $t1, -2 #loop controller
36
+ loop_1:
37
+ addi $t3, $t3, 2
38
+
39
+ ble $t3, 1 , loop_1 #loopback when <=1 is inputted
40
+ beq $t3, 3 , isPrime #when 3 is inputted
41
+ bgt $t3, $t2, exit #when >$t2 exit
42
+
43
+ li $t0, 3 #loop controller #starts from 3 to last
44
+ div $t4, $t3, $t0
45
+ loop_2:
46
+ div $t4, $t3, $t0 #see if divisible or not
47
+ mul $t4, $t4, $t0
48
+ beq $t4, $t3, isNotPrime
49
+
50
+ addi $t0, $t0, 2 #continue the loop
51
+ blt $t0, $t4, loop_2
52
+
53
+ isPrime:
54
+ add $a0 , $t3, $zero
55
+ li $v0, 1
56
+ syscall
57
+ la $a0 , new_line
58
+ li $v0, 4
59
+ syscall
60
+ j loop_1
61
+
62
+ isNotPrime:
63
+ j loop_1
64
+
65
+
66
+ exit:
67
+ li $v0, 10
68
+ syscall
You can’t perform that action at this time.
0 commit comments