Anyone familiar with MIPS floating point instructions?

Click For Summary
The discussion revolves around the challenge of modifying a working integer array code to handle floating point numbers in the SPIM simulator. The user initially presents a functioning integer program that finds the largest number in an array and attempts to adapt it for floating point numbers by replacing integer instructions with floating point equivalents. However, they encounter multiple errors in the process. Key points include the need to use even-numbered registers for floating point operations and the realization that the SPIM simulator does support these operations, which was previously unknown to the user. They express gratitude for the information and plan to further investigate the floating point implementation.
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
 
Technology 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.
 
Learn If you want to write code for Python Machine learning, AI Statistics/data analysis Scientific research Web application servers Some microcontrollers JavaScript/Node JS/TypeScript Web sites Web application servers C# Games (Unity) Consumer applications (Windows) Business applications C++ Games (Unreal Engine) Operating systems, device drivers Microcontrollers/embedded systems Consumer applications (Linux) Some more tips: Do not learn C++ (or any other dialect of C) as a...

Similar threads

  • · Replies 4 ·
Replies
4
Views
21K
  • · Replies 1 ·
Replies
1
Views
3K
  • · Replies 1 ·
Replies
1
Views
10K
  • · Replies 1 ·
Replies
1
Views
6K
Replies
1
Views
2K
  • · Replies 5 ·
Replies
5
Views
10K
  • · Replies 4 ·
Replies
4
Views
5K
  • · Replies 2 ·
Replies
2
Views
5K
  • · Replies 1 ·
Replies
1
Views
7K
Replies
7
Views
10K