-
Notifications
You must be signed in to change notification settings - Fork 8
/
fp_io.asm
76 lines (62 loc) · 1009 Bytes
/
fp_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
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
# basic floating point arithmetic manipulation
.data
float_val: .float 0.001
double_val: .double 0.002
floatMsg: .asciiz "FP number entered is: "
doubleMsg: .asciiz "Double is: "
newline: .asciiz "\n"
.text
main:
# print FP number
l.s $f12, float_val
li $v0, 2
syscall
jal print_new_line
# print double precision number
l.d $f12, double_val
li $v0, 3
syscall
jal print_new_line
# read float
li $v0, 6
syscall
mov.s $f3, $f0
# read double
li $v0, 7
syscall
# print float
li $v0, 4
la $a0, floatMsg
syscall
li $v0,2
mov.s $f12, $f3
syscall
jal print_new_line
# print double
li $v0, 4
la $a0, doubleMsg
syscall
li $v0, 3
mov.d $f12, $f0
syscall
jal print_new_line
# convert float to double
cvt.d.s $f4, $f3
# sum of numbers
add.d $f12, $f4, $f0
li $v0, 3
syscall
jal print_new_line
# difference of numbers
sub.d $f12, $f4, $f0
li $v0, 3
syscall
jal print_new_line
# exit
li $v0, 10
syscall
print_new_line:
li $v0, 4
la $a0, newline
syscall
jr $ra