Advertisement
ChrisH41

Conversions

Feb 8th, 2023
999
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. .data
  2. far: .space 520
  3. kel: .space 520
  4. convert: .float 1.8
  5. kelvin: .float 273.15
  6. space: .asciiz " "
  7. askConversions: .asciiz "Type 0 for celcius to Farenhiet conversions or Type 1 for celcius to Kelvin: "
  8. askKel: .asciiz "Enter an integer between [-20c, 110c]: "
  9. newline: .ascii "\n"
  10.  
  11. .text
  12.  
  13. la $a0, newline
  14. li $v0, 4
  15. syscall
  16.  
  17. # cel to far
  18. li $t0, -20 # start temp
  19. li $t1, 111 # end temp
  20. lwc1 $f0, convert # Conversion needed to convert cel to far
  21. lwc1 $f4, kelvin  # Conversion needed to convert cel to kel
  22. addi $t3, $zero, 0 # Index of array
  23. la $a0, far
  24.  
  25. converter:
  26.     bgt $t0, $t1, end1
  27.  
  28.     mtc1 $t0, $f1       #convert the input value to float
  29.     cvt.s.w $f1, $f1     #convert the input value to float
  30.      
  31.     add.s $f3, $f1, $f4 # add Kelvin constant
  32.     cvt.w.s $f3, $f3        #convert kelvin the float to integer
  33.     mfc1    $t6, $f3       #convert the float to integer
  34.    
  35.     mul.s $f2, $f1, $f0 # multiple temp by 1.8
  36.     cvt.w.s $f2, $f2        #convert the float to integer
  37.         mfc1    $t4, $f2        #convert the float to integer
  38.         addi    $t5, $t4, 32     #add 32 to the integer value which is being multiplied by 1.
  39.         addi $t0, $t0, 1
  40.         sw $t5, far($t3)
  41.         sw $t6, kel($t3)
  42.         addi $t3, $t3, 4
  43.         j converter
  44. end1:
  45.  
  46.  
  47. li $t1, 1 # One for kel
  48. li $t2, 0 # 0 for far
  49. li $t3, 2 # conditional temp value
  50. li $t0, 2 # User input 2 for a null value
  51.  
  52. kelConversions:
  53. beq $t0, $t3, getConversions
  54.  
  55. la $a0, askKel
  56. li $v0, 4
  57. syscall
  58.  
  59. li $v0, 5
  60. syscall
  61. move $t0, $v0 # user input
  62.  
  63. addi $t4, $t0, 20 # get index
  64. mul $t4, $t4, 4   # shift the index by 4 bytes
  65.  
  66. lw $t0, kel($t4) # get convsion from array
  67.  
  68. li $v0, 1       # print num
  69. move $a0, $t0
  70. syscall
  71.  
  72. la $a0, newline
  73. li $v0, 4
  74. syscall
  75.  
  76. li $t6, 520
  77. li $t4, 0
  78.  
  79.  
  80.  
  81. li $t0, 2
  82. j getConversions
  83.  
  84. li $t1, 1 # One for kel
  85. li $t2, 0 # 0 for far
  86. li $t3, 2 # conditional temp value
  87. li $t0, 2 # User input 2 for a null value
  88.  
  89.  
  90. farConversions:
  91. beq $t0, $t3, getConversions
  92.  
  93. la $a0, askKel
  94. li $v0, 4
  95. syscall
  96.  
  97. li $v0, 5
  98. syscall
  99. move $t0, $v0 # user input
  100.  
  101. addi $t4, $t0, 20 # get index
  102. mul $t4, $t4, 4   # shift the index by 4 bytes
  103.  
  104. lw $t0, far($t4) # get convsion from array
  105.  
  106. li $v0, 1       # print num
  107. move $a0, $t0
  108. syscall
  109.  
  110. la $a0, newline
  111. li $v0, 4
  112. syscall
  113.  
  114. li $t0, 2
  115. j getConversions
  116.  
  117.  
  118. getConversions:
  119. beq $t1, $t0, kelConversions
  120. beq $t2, $t0, farConversions
  121.  
  122. la $a0, askConversions
  123. li $v0, 4
  124. syscall
  125.  
  126. li $v0, 5
  127. syscall
  128. move $t0, $v0 # user input
  129.  
  130. la $a0, newline
  131. li $v0, 4
  132. syscall
  133. j getConversions
  134.  
  135.  
  136.  
  137.  
  138.  
  139.  
  140.  
  141.  
  142.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement