Write a MIPS program that finds a fixed-point of the function f(x) = x*x - 2*x +
ID: 3535058 • Letter: W
Question
Write a MIPS program that finds a fixed-point of the
function f(x) = x*x - 2*x + 1. There are two fixed-points for this function, but I want you to
find the one that is between 0 and 1. The fixed-point can be found iteratively by starting with a
value of x between 0 and 1, computing f(x) and taking the average between x and f(x). Then
repeat the calculation with this average as the new value for x. In other words, let g(x) compute
the next estimate for the fixed-point as g(x) = (x + f(x)/2 = (x*x – x + 1)/2. Then compute the
assignment statement x = g(x) many times. Write a MIPS program that does this computation
using double precision numbers. It will be sufficient for this assignment to execute the
assignment statement x = g(x) exactly 10 times and store the double precision value of x in
double precision register $f0. Start with 1.0 as the initial value of x.
*Must be in MIPS assembly language to recieve credit
Explanation / Answer
.text
.globl main
main:
li.d $f0, 1.0
li.d $f2, 1.0
li.d $f4, 0.5
loop:
bge $t0, 10, end
mov.d $f6, $f0
mul.d $f6, $f6, $f6
sub.d $f6, $f6, $f0
add.d $f6, $f6, $f2
mul.d $f6, $f6, $f4
mov.d $f0, $f6
addi $t0, $t0, 1
j loop
end:
li $v0, 3
mov.d $f12, $f0
syscall
li $v0, 10
syscall
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.