This is a MIPS assembly language program to demonstrate how different weather temperature formats can be converted from one to another. Commonly used temperature in the United States in weather forecasts is Fahrenheit where as Celsius is another format that is used mostly in Europe and Asia. This program gives user two options. Options are as follows: Press 1 to convert Celsius to Fahrenheit and Press 2 to convert Fahrenheit to Celsius. If option 1 is chosen, the program then asks user to enter temperature in Celsius and then prints the temperature in Fahrenheit and vice versa. This program also demonstrates how to use floating point numbers in MIPS.

.data
inputc:	.asciiz	"Press 1 to convert Celcius into Farenheit"
inputf:	.asciiz	"\nPress 2 to convert Farenheit into Celcius"
ch:	.asciiz	"\nEnter your choice: "
in:	.asciiz	"Enter Value: "
result:	.asciiz	"Result is: "
f:	.float 0.555555
c:	.float 1.8
m:	.float 32.0

.text
.globl main
main:
	la $a0,	inputc
	li $v0, 4
	syscall
	
	la $a0,	inputf
	li $v0, 4
	syscall
	
	la $a0,	ch
	li $v0, 4
	syscall
	
	li $v0,5
	syscall
	
	move $t0,$v0
		
	beq $t0,1,Celcius
	beq $t0,2,Farenheit
	
Celcius:
	la $a0,	in
	li $v0, 4
	syscall
	
	li $v0,6
	syscall
	
	mov.s $f3,$f0	
	l.s $f4,c
	mul.s $f5,$f3,$f4
	l.s $f6,m
	add.s $f7,$f5,$f6
	
	la $a0,	result
	li $v0, 4
	syscall
	
	mov.s $f12,$f7
	li $v0,2
	syscall
	
	li $v0,10
	syscall
		
Farenheit:
	la $a0,	in
	li $v0, 4
	syscall
	
	li $v0,6
	syscall
	
	mov.s $f3,$f0	
	l.s $f4,m
	sub.s $f5,$f3,$f4
	l.s $f6,f
	mul.s $f7,$f5,$f6
	
	la $a0,	result
	li $v0, 4
	syscall
	
	mov.s $f12,$f7
	li $v0,2
	syscall
	
	li $v0,10
	syscall

Output in MARS

c2f

Tagged with: MIPS AssemblySource Code
 

Leave a Reply

Your email address will not be published.

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

 

Looking for something?

Use the form below to search the site:


Still not finding what you're looking for? Drop a comment on a post or contact us so we can take care of it!

Related News Feeds

Set your Twitter account name in your settings to use the TwitterBar Section.