-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlab10b.s
More file actions
74 lines (57 loc) · 1.65 KB
/
Copy pathlab10b.s
File metadata and controls
74 lines (57 loc) · 1.65 KB
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
# func1.s
.data
before: .asciiz "Before function\n"
resAdd: .asciiz "A + B is: "
resSub: .asciiz "A - B is: "
newline: .asciiz "\n"
.text
main:
li $t0, 5 # hard coded value for A
li $t1, 3 # hard coded value for B
li $v0, 4 # system call code for print_string
la $a0, before # address of string to print
syscall # print the string
li $v0, 4 # system call code for print_string
la $a0, resAdd # address of string to print
syscall # print the string
# TODO: setup the arguments for function call doAdd
move $a0, $t0
move $a1, $t1
jal doAdd # Make a function call to doAdd()
#TODO: what exactly does jal do? Lookup the reference sheet
# TODO: print the return value of doAdd
move $t2, $v0
li $v0, 1
move $a0, $t2
syscall
li $v0, 4 # system call code for print_string
la $a0, newline # address of string to print
syscall # print the string
li $v0, 4 # system call code for print_string
la $a0, resSub # address of string to print
syscall # print the string
# TODO: setup the arguments for function call doSub
move $a0, $t0
move $a1, $t1
jal doSub # Make a function call to doSub()
# TODO: print the return value of doSub
move $t2, $v0
li $v0, 1
move $a0, $t2
syscall
li $v0, 4 # system call code for print_string
la $a0, newline # address of string to print
syscall # print the string
# End of main, make a syscall to "exit"
li $v0, 10 # system call code for exit
syscall # terminate program
# start of function doAdd()
doAdd:
add $v0, $a0, $a1
# TODO: what need to be done here?
jr $ra
# start of function doSub()
doSub:
sub $v0, $a0, $a1
# TODO: what need to be done here?
jr $ra