Click here to Skip to main content
15,887,746 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I want to write this code:

C++
y= 0.4*x+1 


but I have some errors in MIPS assembly

[Edit - Added from comment]
I have an integer value in register $t1 and I want to multiply it with 0.4 but it has error in the second line:
assembler
li.s $f0, 0.4
mul.d $f1, $f0, $t1
mfhi $a2
mflo $v0

# print the result
li $v0, 2 # load appropriate system call code into reg $v0
la $a0, 0($v0) # load address of string to be printed on $a0
syscal

[/Edit]
Posted
Updated 30-Oct-15 2:03am
v2
Comments
phil.o 30-Oct-15 7:22am    
Which errors?
amin.j 30-Oct-15 7:33am    
I have an integer value in register $t1 and I want to multiply it with 0.4 but it has error in the second line:

li.s $f0, 0.4
mul.d $f1, $f0, $t1
mfhi $a2
mflo $v0

# print the result
li $v0, 2 # load appropriate system call code into reg $v0
la $a0, 0($v0) # load address of string to be printed on $a0
syscal
Jochen Arndt 30-Oct-15 8:18am    
Even for those who know MIPS assembler (I don't), it would be helpful to know the error message.

Not knowing the assembler or starting with it, I would lookup the mul.d instruction and check if the arguments are correct (here especially if an integer register is allowed as third argument).
Philippe Mori 30-Oct-15 13:47pm    
Write equivalent code in C or similar language. Compile the code and look at the disassembly...

1 solution

Quote:
mul.d $f1, $f0, $t1
I guess you have to use a floating point (FPU) register (instead of $t1) as target.
 
Share this answer
 
Comments
ridoy 30-Oct-15 9:01am    
yes, thats the point.
amin.j 30-Oct-15 10:25am    
As I know:

mul.d $destination, $source, $source

the third one is the second float pint for multiplying. But, my case is different, I want to multiply one integer in $t1 with a float in $f0; how can I do that?
Jochen Arndt 30-Oct-15 13:32pm    
You must convert the integer to a floating point and pass the destination register of the conversion to the multiply function.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900