Post

MIPS celsius to fahrenheit

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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
## Celsius to fahrenheit

  


.data
msg:
.asciiz "Enter celsius : "
const9:
.float 9.0
const5:
.float 5.0
const32:
.float 32.0
zeroF:
.float 0.0

  


  


.text

.globl main
main:
## Expand stack and save $ra

addi $sp, $sp, -4

sw $ra, ($sp)




li $v0, 4
## print\_str syscall number

la $a0, msg
## arg0 : msg

syscall




li $v0, 6
## read\_float syscall number

syscall
## $f0 - user input float number




jal c2f




li $v0, 2
## print\_float syscall number

lwc1 $f4, zeroF
## $f4 = 0.0

add.s $f12, $f0, $f4
## move $f0 to $f12. $f12 is arg.

syscall




## Shrink stack and load $ra

lw $ra, ($sp)

addi $sp, $sp, 4




jr $ra



c2f:
lwc1 $f16, const5
## $f16 = 5.0 (ldc1, load double coprocess1)

lwc1 $f18, const9
## $f18 = 9.0

div.s $f18, $f18, $f16
## $f18 = 9.0 / 5.0

mul.s $f0, $f0, $f18
## $f0 = $f0 \* 9/5

lwc1 $f16, const32

add.s $f0, $f0, $f16
## $f0 = $f0 + 32

jr $ra

실수를 계산하는 coprocessor 레지스터($f0, $f1, ...)와 정수 레지스터간 데이터 교환

1
2
mtc1 $t0, $f0    #move to coprocess1
mfc1 $t0, $f0    #move from coprocess1

실수↔정수 형변환

1
2
cvt.s.w $f0, $f0    # Convert to Single from Integer
cvt.w.s $f0, $f0    # Convert to Integer from Single
This post is licensed under CC BY 4.0 by the author.