Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- .data
- far: .space 520
- kel: .space 520
- convert: .float 1.8
- kelvin: .float 273.15
- space: .asciiz " "
- askConversions: .asciiz "Type 0 for celcius to Farenhiet conversions or Type 1 for celcius to Kelvin: "
- askKel: .asciiz "Enter an integer between [-20c, 110c]: "
- newline: .ascii "\n"
- .text
- la $a0, newline
- li $v0, 4
- syscall
- # cel to far
- li $t0, -20 # start temp
- li $t1, 111 # end temp
- lwc1 $f0, convert # Conversion needed to convert cel to far
- lwc1 $f4, kelvin # Conversion needed to convert cel to kel
- addi $t3, $zero, 0 # Index of array
- la $a0, far
- converter:
- bgt $t0, $t1, end1
- mtc1 $t0, $f1 #convert the input value to float
- cvt.s.w $f1, $f1 #convert the input value to float
- add.s $f3, $f1, $f4 # add Kelvin constant
- cvt.w.s $f3, $f3 #convert kelvin the float to integer
- mfc1 $t6, $f3 #convert the float to integer
- mul.s $f2, $f1, $f0 # multiple temp by 1.8
- cvt.w.s $f2, $f2 #convert the float to integer
- mfc1 $t4, $f2 #convert the float to integer
- addi $t5, $t4, 32 #add 32 to the integer value which is being multiplied by 1.
- addi $t0, $t0, 1
- sw $t5, far($t3)
- sw $t6, kel($t3)
- addi $t3, $t3, 4
- j converter
- end1:
- li $t1, 1 # One for kel
- li $t2, 0 # 0 for far
- li $t3, 2 # conditional temp value
- li $t0, 2 # User input 2 for a null value
- kelConversions:
- beq $t0, $t3, getConversions
- la $a0, askKel
- li $v0, 4
- syscall
- li $v0, 5
- syscall
- move $t0, $v0 # user input
- addi $t4, $t0, 20 # get index
- mul $t4, $t4, 4 # shift the index by 4 bytes
- lw $t0, kel($t4) # get convsion from array
- li $v0, 1 # print num
- move $a0, $t0
- syscall
- la $a0, newline
- li $v0, 4
- syscall
- li $t6, 520
- li $t4, 0
- li $t0, 2
- j getConversions
- li $t1, 1 # One for kel
- li $t2, 0 # 0 for far
- li $t3, 2 # conditional temp value
- li $t0, 2 # User input 2 for a null value
- farConversions:
- beq $t0, $t3, getConversions
- la $a0, askKel
- li $v0, 4
- syscall
- li $v0, 5
- syscall
- move $t0, $v0 # user input
- addi $t4, $t0, 20 # get index
- mul $t4, $t4, 4 # shift the index by 4 bytes
- lw $t0, far($t4) # get convsion from array
- li $v0, 1 # print num
- move $a0, $t0
- syscall
- la $a0, newline
- li $v0, 4
- syscall
- li $t0, 2
- j getConversions
- getConversions:
- beq $t1, $t0, kelConversions
- beq $t2, $t0, farConversions
- la $a0, askConversions
- li $v0, 4
- syscall
- li $v0, 5
- syscall
- move $t0, $v0 # user input
- la $a0, newline
- li $v0, 4
- syscall
- j getConversions
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement