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.

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

.text
.globl main

lui \$11,0x1000 # Init base register
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``````
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, learning, and sharing knowledge.