Anyone familiar with MIPS floating point instructions?

Click For Summary
SUMMARY

This discussion focuses on implementing floating point operations in MIPS assembly language using the SPIM simulator. The user attempted to adapt an integer-based algorithm for finding the largest number in an array to work with floating point numbers, encountering several errors in the process. Key points include the need to utilize even-numbered registers for floating point operations and the correct usage of instructions such as l.s for loading single-precision floats and add.s for addition. The user also referenced a helpful resource detailing SPIM's support for floating point instructions.

PREREQUISITES
  • Understanding of MIPS assembly language syntax and structure
  • Familiarity with floating point operations in MIPS
  • Knowledge of the SPIM simulator and its capabilities
  • Experience with basic algorithm design for array manipulation
NEXT STEPS
  • Study MIPS floating point instructions, specifically l.s and add.s
  • Explore the SPIM simulator documentation for floating point support
  • Learn about register conventions in MIPS, particularly the use of even-numbered registers for floating point
  • Implement error handling in MIPS assembly for debugging floating point operations
USEFUL FOR

Assembly language programmers, computer architecture students, and anyone working with MIPS assembly in the SPIM simulator, particularly those interested in floating point arithmetic and array processing.

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.
 

Similar threads

  • · Replies 4 ·
Replies
4
Views
22K
  • · Replies 1 ·
Replies
1
Views
3K
  • · Replies 1 ·
Replies
1
Views
11K
  • · 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