Hey there!
I had to write a programme for MIPS/SPIM, which reads floating point numbers and returns them bit by bit at the shell. So this is, what I managed to write:
.data
var1: .float 0.00
var2: .float 2.0
var3: .float -0.123
txt2: .asciiz "\n"
.text
main:
addi $sp, $sp, -20 # decrement stack pointer
l.s $f0, var3 # load var3 in $f0
s.s $f0, 20($sp) # push $f0 on stack
addi $sp, $sp, -20 # decrement stack pointer
l.s $f1, var2 # load var2 in $f1
s.s $f1, 20($sp) # push $f1 on stack
addi $sp, $sp, -20 # decrement stack pointer
l.s $f2, var1 # load var1 in $f2
s.s $f2, 20($sp) # push $f2 on stack
li $t3, 3 # $t3 = 3: number of floats
for1:
sub $t3, $t3, 1 # decrement $t3
l.s $f0, 4($sp) # load first byte from stack in $f0
addi $sp, $sp, 4 # increment stack pointer
li $t7, 1 # preparation: $t7 = 1
li $t6, 0 # preparation: $t6 = 0
li $t0, 1 # preparation: $t0 = 1
mfc1 $t2, $f0 # move from coprocessor: $t2 = $f0
for2:
and $t1, $t2, $t0 # logical and: $t1 = $t2 AND $t0
sll $t0, $t0, 1 # shift left logical: $t0 = $t0 * 2^1
bne $zero, $t1, case_1 # if $t1 /= 0 branch to case_1
addi $sp, -4 # decrement stack pointer
sw $zero, 4($sp) # push $zero (=0) on stack
b go_on # branch to go_on
case_1:
addi $sp, -4 # decrement stack pointer
sw $t7, 4($sp) # push $t7 (=1) on stack
go_on:
addi $t6, $t6, 1 # increment $t6
bne $zero, $t0, for2 # if $t0 /= 0 branch to for2
li $v0, 1 # print_int
for3:
lw $a0, 4($sp) # load in $a0 value from stack on address 4($sp)
addi $sp, 4 # increment stack pointer
syscall # print
sub $t6, $t6, 1 # decrement $t6
bne $zero, $t6, for3 # if $t6 /= 0 branch to for3
li $v0, 4 # print_string
la $a0, txt2 # load in $a0 address txt2
syscall # print "\n"
bne $zero, $t3, for1 # if $t3 /= 0 branch to for1
li $v0, 10 # exit
syscall
It works, but somehow I've got the impression, that it always returns the same numbers (even if I've changed the floating point numbers in the .data-section).
I've got no idea, where the problem could be... Maybe someones got a hint for me?