-
Notifications
You must be signed in to change notification settings - Fork 8
/
mul_div_fp.asm
81 lines (69 loc) · 1.07 KB
/
mul_div_fp.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
# multiply and divide numbers
.data
welcome: .asciiz "Enter two integer numbers: "
quotient: .asciiz "Quotient: "
remainder: .asciiz "Remainder: "
decimal: .asciiz "Quotient in decimal: "
newline: .asciiz "\n"
.text
main:
# welcome message
li $v0, 4
la $a0, welcome
syscall
# read two integers
li $v0, 5
syscall
move $t0, $v0
li $v0, 5
syscall
move $t1, $v0
# print the integers
li $v0, 1
move $a0, $t0
syscall
jal print_new_line
li $v0, 1
move $a0, $t1
syscall
jal print_new_line
# multiply integers
mul $a0, $t0, $t1
li $v0, 1
syscall
jal print_new_line
# divide integers (quotient, remainder)
div $t0, $t1
li $v0, 4
la $a0, quotient
syscall
li $v0, 1
mflo $a0
syscall
jal print_new_line
li $v0, 4
la $a0, remainder
syscall
li $v0, 1
mfhi $a0
syscall
jal print_new_line
# divide integers (FP answer)
mtc1 $t0, $f12
cvt.s.w $f3, $f12
mtc1 $t1, $f12
cvt.s.w $f4, $f12
div.s $f12, $f3, $f4
li $v0, 4
la $a0, decimal
syscall
li $v0, 2
syscall
# exit
li $v0, 10
syscall
print_new_line:
li $v0, 4
la $a0, newline
syscall
jr $ra