-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMedianNumbers.asm
91 lines (66 loc) · 1.14 KB
/
MedianNumbers.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
# MedianNumbers.asm program
# CS 64, Z.Matni, [email protected]
#
.data
# TODO: Complete these declarations / initializations
nextNum: .asciiz "Enter the next number:\n"
med: .asciiz "Median: "
#Text Area (i.e. instructions)
.text
main:
li $v0, 4
la $a0,nextNum
syscall
li $v0, 5
syscall
move $t0, $v0
li $v0, 4
la $a0,nextNum
syscall
li $v0, 5
syscall
move $t1, $v0
li $v0, 4
la $a0,nextNum
syscall
li $v0, 5
syscall
move $t2, $v0
blt $t0, $t1, t1GreaterThan
blt $t1, $t0, t0GreaterThan
t1GreaterThan:
blt $t1, $t2, t1IsMedian
blt $t2, $t0, t0IsMedian
blt $t0, $t2, t2IsMedian
t0GreaterThan:
blt $t0, $t2, t0IsMedian
blt $t2, $t1, t1IsMedian
blt $t1, $t2, t2IsMedian
t0IsMedian:
li $v0, 4
la $a0, med
syscall
li $v0, 1
move $a0, $t0
syscall
j exit
t1IsMedian:
li $v0, 4
la $a0, med
syscall
li $v0, 1
move $a0, $t1
syscall
j exit
t2IsMedian:
li $v0, 4
la $a0, med
syscall
li $v0, 1
move $a0, $t2
syscall
j exit
exit:
# Exit
li $v0, 10
syscall