Anyone familiar with MIPS floating point instructions?

Join the discussion
Ask a follow-up here, or get your own question answered by working scientists, mathematicians and engineers — people, not an autocomplete.
Real named experts · corrections over time · the nuance an AI answer skips
2 replies · 9K views
trouty323
Messages
23
Reaction score
0
Hello all. My task here was to have an array of floating point numbers, find the largest in the array, and store it back into the array. The first code shows a properly working integer interpretation of the task, and the second shows my interpretation of the floating point. I simply tried to swap out any instruction for integers to make it floating point, but I'm getting several errors. I didn't think it would be this complicated.

Code:
	.data

.word 7, 39, 42, 16, 15, 21, 3, 2, 37, 11, 32, 28, 40, 27, 20

	.text
	.globl main

main:

lui $s0, 0x1001		# base address
add $t0, $t0, $zero	# index count
add $t1, $t1, $zero	# max element, $t1 = 0
addi $t5, $t5, 15	# number of elements
add $t2, $t2, $s0	# offset plus base

Loop:

beq $t0, $t5, Exit	# branch if counter is equal to number of elements in array
lw $t3, 0($t2)		# reading first element
addi $t0, $t0, 1	# increment counter by 1
addi $t2, $t2, 4	# increment offset by 4
slt $t4, $t1, $t3	# $t4 = 1 if $t1 is less than $t3, otherwise $t4 = 0
beq $t4, $zero, Loop	# branch to loop if value in $t4 is equal to value in $zero
add $t1, $t3, $zero

j Loop

Exit:

sw $t1, 0($t2)		# store highest back into array

li $v0, 10 		# syscall to terminate
syscall

Code:
	.data

.float 7.5, 39.2, 42.4, 16.1, 15.3, 21.6, 3.7, 2.6, 37.7, 11.5, 32.2, 28.3, 40.8, 27.7, 20.3

	.text
	.globl main

main:

	lui $f11, 0x1001	# base address
	add $t0, $t0, $zero	# index count
	add.s $f4, $f4, $zero	# max element, $f4 = 0
	addi $t5, $t5, 15	# number of elements
	add.s $f5, $f5, $f11	# offset plus base

Loop:

	beq $t0, $t5, Exit	# branch if counter is equal to number of elements in array
	l.s $f6, ($f5)		# reading first element
	addi $t0, $t0, 1	# increment counter by 1
	addi.s $f5, $f5, 4	# increment offset by 4
	c.lt.s $t4, $f4, $f6	# $t4 = 1 if $f4 is less than $f6, otherwise $t4 = 0
	beq $t4, $zero, Loop	# branch to loop if value in $t4 is equal to value in $zero
	add $f4, $f6, $zero

j Loop

Exit:

	sw $f4, 0($f5)		# store highest back into array

	li $v0, 10 		# syscall to terminate
	syscall
 
Physics news on Phys.org
I'm using the SPIM simulator, but wasn't aware that it supported floating point operations. I found this website - http://www.doc.ic.ac.uk/lab/secondyear/spim/node20.html - that seems to be talking about the SPIM simulator. Maybe this will be of use to you.

One thing that was mentioned is that "floating point operations only use even-numbered registers--including instructions that operate on single floats".
 
Thanks for the information. I'll look over it and see what I can figure out.