Anyone familiar with MIPS floating point instructions?

In summary, the first code shows how to store a floating point number in an integer array. The second code shows how to store a floating point number in an integer array using the SPIM simulator.
  • #1
trouty323
24
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
  • #2
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".
 
  • #3
Thanks for the information. I'll look over it and see what I can figure out.
 

What is MIPS and how is it related to floating point instructions?

MIPS (Microprocessor without Interlocked Pipeline Stages) is a type of computer architecture that is commonly used in embedded systems, such as game consoles and routers. MIPS floating point instructions are a set of instructions designed specifically for performing arithmetic operations on floating point numbers in the MIPS architecture.

What are some examples of MIPS floating point instructions?

Some examples of MIPS floating point instructions include add.s (addition), sub.s (subtraction), mul.s (multiplication), div.s (division), and mov.s (moving data).

What is the difference between MIPS floating point instructions and integer instructions?

MIPS floating point instructions are used for performing operations on floating point numbers, while integer instructions are used for performing operations on whole numbers. The main difference between the two is the way they handle and store numbers with decimal points.

Are there any limitations to using MIPS floating point instructions?

Yes, there are some limitations to using MIPS floating point instructions. For example, they are not suitable for performing complex mathematical operations, and they have limited precision compared to other floating point instruction sets.

How can I learn more about MIPS floating point instructions?

You can learn more about MIPS floating point instructions by consulting the MIPS architecture manual, which provides detailed information and examples of how to use these instructions in programming. You can also find online resources and tutorials that can help you understand and use MIPS floating point instructions.

Similar threads

  • Programming and Computer Science
Replies
4
Views
20K
  • Programming and Computer Science
Replies
1
Views
2K
  • Programming and Computer Science
Replies
1
Views
8K
  • Engineering and Comp Sci Homework Help
Replies
4
Views
3K
  • Engineering and Comp Sci Homework Help
Replies
1
Views
1K
  • Engineering and Comp Sci Homework Help
Replies
2
Views
4K
  • Programming and Computer Science
Replies
1
Views
5K
  • Programming and Computer Science
Replies
5
Views
9K
  • Engineering and Comp Sci Homework Help
Replies
7
Views
2K
  • Programming and Computer Science
Replies
1
Views
6K
Back
Top