-
Notifications
You must be signed in to change notification settings - Fork 0
/
average.asm
70 lines (54 loc) · 874 Bytes
/
average.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
.data
msg1: .asciiz "Enter first integer:"
msg2: .asciiz "Enter the 2nd integer:"
msg3: .asciiz "Enter the 3rd integer"
msg4: .asciiz "Your average is: "
.text
.globl main
.ent main
main:
li $v0,4
la $a0,msg1
syscall
li $v0,5
syscall
move $t0,$v0
li $v0,4
la $a0,msg2
syscall
li $v0,5
syscall
move $t1,$v0
li $v0,4
la $a0,msg3
syscall
li $v0,5
syscall
move $t2,$v0
move $a0, $t0
move $a1, $t1
move $a2, $t2
jal Average
move $t0, $v0
li $v0,4
la $a0,msg4
syscall
li $v0,1
move $a0, $t0
syscall
li $v0, 10
syscall
.end main
Average:
addi $sp, $sp, -4
sw $s0, 0($sp)
add $s0, $a0, $a1
add $s0, $s0, $a2 # a+b+c
li $t4, 3
div $s0, $t4
mflo $t5
mfhi $t6
lw $s0, 0($sp)
addi $sp, $sp, 4
move $v0, $t5
jr $ra