-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathLAB2.asm
More file actions
76 lines (57 loc) · 1.92 KB
/
LAB2.asm
File metadata and controls
76 lines (57 loc) · 1.92 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
75
76
.data
firstIntMsg: .asciiz "Enter 1st integer: "
opCharMsg: .asciiz "Enter operation symbol: "
secondIntMsg: .asciiz "\nEnter 2nd integer: "
wrongChar: .asciiz "You have entered an inappropriate operation character!"
resultMsg: .asciiz "The result is: "
firstInt: .word 0
opChar: .asciiz ""
secondInt: .word 0
result: .word 0
.text
main:
la $a0, firstIntMsg #Load and print string asking for the first integer
li $v0, 4
syscall
li $v0, 5 #Take user input for the first integer
syscall
sw $v0, firstInt
la $a0, opCharMsg #Load and print string asking for the operation character
li $v0, 4
syscall
li $v0,12 #Take user input for the operation character
syscall
sw $v0, opChar
la $a0, secondIntMsg #Load and print string asking for the second integer
li $v0, 4
syscall
li $v0, 5 #Take user input for the second integer
syscall
sw $v0, secondInt
lb $s1, firstInt #Load the first integer in s1
lb $s0, opChar #Load the operation character in s0
lb $s2, secondInt #Load the second integer in s2
beq $s0, 0x0000002b, addition #+ #If the given character belongs to an operation...
beq $s0, 0x0000002d, subtraction #- #...branch to that operation
beq $s0, 0x0000002a, multiplication #*
beq $s0, 0x0000002f, division #/
la $a0, wrongChar #Load and print string for wrong operation character
li $v0, 4
syscall
j exit
addition: add $s1, $s1, $s2 #Adding the two integers
j print
subtraction: sub $s1, $s1, $s2 #Subtracting the two integers
j print
multiplication: mul $s1, $s1, $s2 #Multipling the two integers
j print
division: div $s1, $s1, $s2 #Dividing the two integers
j print
print: la $a0, resultMsg #Load and print string "The result is: "
li $v0, 4
syscall
li $v0, 1 #Print the integer result
move $a0,$s1
syscall
exit: li $v0, 10 #End program
syscall