-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathIO.asm
50 lines (40 loc) · 976 Bytes
/
IO.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
# Start .data segment (data!)
.data
msg1: .asciiz "Enter A: "
msg2: .asciiz "Enter B: "
msg3: .asciiz "A + B = "
newline: .asciiz "\n"
.text
main:
# Print string msg1
li $v0,4 # print_string syscall code = 4
la $a0, msg1 # load the address of msg
syscall
# Get input A from user and save
li $v0,5 # read_int syscall code = 5
syscall
move $t0,$v0 # syscall results returned in $v0
# Print string msg2
li $v0,4 # print_string syscall code = 4
la $a0, msg2 # load the address of msg2
syscall
# Get input B from user and save
li $v0,5 # read_int syscall code = 5
syscall
move $t1,$v0 # syscall results returned in $v0
# Math!
add $t0, $t0, $t1 # A = A + B
# Print string msg3
li $v0, 4
la $a0, msg3
syscall
# Print sum
li $v0,1 # print_int syscall code = 1
move $a0, $t0 # int to print must be loaded into $a0
syscall
# Print \n
li $v0,4 # print_string syscall code = 4
la $a0, newline
syscall
li $v0,10 # exit
syscall