Computer Engineering Project Collection

-->

Saturday, January 10, 2009

MIPS Assembly Introduction

This is an introduction program to get used into MIPS Assembly language. The codes compiled and simulated using PC SPIM ver 7.00. With this little program, we can see what happens in the registers and memory, debugging the code line per line, etc. It also has a console so that the input/output may be displayed.

The first simple program is to convert Farenheit temperature degree into Celcius temperature degree. The code is :

.data
enter: .asciiz "Enter temperature in farenheit: "
cel1: .asciiz "It's the same as "
cel2: .asciiz " celcius\n"
.text
.globl main
main: addu $s0, $ra, $0
li $v0,4
la $a0,enter
syscall
li $v0,5
syscall
add $t0,$0,$v0
sub $t0,$t0,32
li $t1,5
li $t2,9
mult $t0,$t1
mflo $t3
divu $t3,$t2
mflo $t4
li $v0,4
la $a0,cel1
syscall
add $a0,$0,$t4
li $v0,1
syscall
li $v0,4
la $a0,cel2
syscall
addu $ra, $0, $s0
jr $ra


it uses syscall to display some text on the console, as well as taking inputs from there. The parameters for syscall is regulated by register $v0.

The simulation result is like this :
(click to enlarge)

Labels: , ,

0 Comments:

Post a Comment

Subscribe to Post Comments [Atom]



<< Home