We're a community of 1076K IT Pros here for help, advice, solutions, professional growth and fun. Join us!
1,075,831 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Start New Discussion Reply to this Discussion

Compute A Polynomial Using Horners Method Code Question

I need to Compute 2x4 +7x3 -15x2 +3x+2 Using Horners Method. When I run this in QTSpim it doesn't give me any errors but I'm just wondering if everything is running completely right. For instance did I call "x" correctly?

I'm trying to load the value for x from memory by using an lw instruction. Set up a base register to use with the instruction. After the polynomial was calculated I stored it in memory with an sw instruction (using the same base register). I just want to be sure I'm doing this right.

Thank you for your assistance.

## $10 Holds X
## $11 is the base register

.text
.globl main

lui $11,0x1000 # Init base register
lw $10,0($11) # Load x
sll $0,$0,0 # Break/Refresh
ori $1, $0, 2	 # Put 2 in register 1
ori $10, $0, 0	 # Put x as the placeholder for X in register 10
multu $1, $10	 # Multiply register 1 by "X" (register 10)
mflo $1	 # Move low result to register 1
addiu $1, $1, 7	 # Add 7 to register 1 (2x + 7)
multu $1, $10	 # Multiply register 1 by register 10 (2x^2 + 7x)
mflo $1	 # Move low result to register 1
addu $1, $1, -15	 # Subtract 15 from register 1, result in register 1
multu $1, $10	 # Multiply register 1 by x. (2x^3 + 7x^2 -15x)
mflo $1	 # Move low result to register 1
addiu $1, $1, 3	 # Add 3 to register 1 (2x^3 + 7x^2 -15x + 3)
multu $1, $10	 # Multiply register 1 by x (2x^4 + 7x^3 -15x^2 + 3x)
mflo $1	 # Move low result to register 1
addiu $1, $1, 2	 # Add 2 to register 1 (2x^4 + 7x^3 -15x^2 + 3x + 2)
sw $10,0($11) # Store word
sll $0,$0,0 # target of the branch

x: .word 1
result: .word 0


##End of file
1
Contributor
0
Replies
1
View
Question
Answered
userct
Newbie Poster
15 posts since Feb 2012
Reputation Points: 10
Solved Threads: 0
Skill Endorsements: 0
Question Self-Answered as of 1 Year Ago

This question has already been solved: Start a new discussion instead

Post: Markdown Syntax: Formatting Help
 
You
View similar articles that have also been tagged:
 
© 2013 DaniWeb® LLC
Page rendered in 0.0524 seconds using 2.66MB