MIPS celsius to fahrenheit
```py
# 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, ...``)와 정수 레지스터간 데이터 교환
```py
mtc1 $t0, $f0 #move to coprocess1
mfc1 $t0, $f0 #move from coprocess1
```
실수↔정수 형변환
```py
cvt.s.w $f0, $f0 # Convert to Single from Integer
cvt.w.s $f0, $f0 # Convert to Integer from Single
```
'OS > Micro' 카테고리의 다른 글
[ARM OS image] Android / Linaro (0) | 2017.10.15 |
---|---|
[QEMU] armv7 Emulate (0) | 2017.10.14 |
ARM Assembly (0) | 2017.10.08 |