Write an MIPS assembly program which gets two double numbers
Write an MIPS assembly program which gets two double numbers from the user. These two numbers are height in terms of feet and inches. You are asked to write a program to convert the height into meters (stored as a double number).
a. The program should print a meaningful phrase for each input, and the result.
i. “Enter the height in feet”
ii. “Enter the height in inches”
iii. “Height is 1.76 meters”
b. Is it possible to use integer registers instead of float registers?
c. Modify your program to convert the height into centimeters as well.
Solution
Here is the MIPS code tested in MARS
.data
feetMsg: .asciiz \"Enter the height in feet: \"
inchMsg: .asciiz \"Enter the height in inches: \"
heightis: .asciiz \"\ Height is \"
meters: .asciiz \" meters\"
centimeters: .asciiz \" centimeters\"
inch2Meters: .float 0.0254
twelve: .float 12.0
hundred: .float 100.0
.text
main:
#promt the user to enter height in feet
li $v0, 4
la $a0, feetMsg
syscall
#get user input as a floating point value
li $v0, 6
syscall
mov.s $f1, $f0 #save the input to $f1
#promt the user to enter height in inches
li $v0, 4
la $a0, inchMsg
syscall
#get user input as a floating point value
li $v0, 6
syscall
mov.s $f2, $f0 #save the input into $f2
# f3 = 12 ; f1 = f1 * f3 i.e convert feet to inches by multiplying 12
l.s $f3, twelve
mul.s $f1, $f1, $f3
#add the remaining feet from user input also to f1 to get total feet length
add.s $f1, $f1, $f2
#now convert feet to meters uisng conversion factor i.e multiply inches x 0.0254 to get meters
l.s $f3, inch2Meters
mul.s $f1, $f1, $f3
#display the message \"height is \"
li $v0, 4
la $a0, heightis
syscall
#display the result of conversion stored in f1
li $v0, 2
mov.s $f12, $f1
syscall
#display the word \" meters\"
li $v0, 4
la $a0, meters
syscall
#now to convert meters to centimeters, simply multiply by 100, store back in $f1
l.s $f3, hundred
mul.s $f1, $f1, $f3
#display message \"height is \"
li $v0, 4
la $a0, heightis
syscall
#display the number stored in f1 (height in cms )
li $v0, 2
mov.s $f12, $f1
syscall
#display the word \" centimeters\"
li $v0, 4
la $a0, centimeters
syscall
=====
output
Enter the height in feet: 5
Enter the height in inches: 10
Height is 1.778 meters
Height is 177.8 centimeters

