> MIPS32 Assembly language program question?

MIPS32 Assembly language program question?

Posted at: 2014-12-18 
A C for or do-while loop can be converted directly into assembly

language, but it may be easier to first convert the loop into an equivalent while loop,

Given:

for (init-expr; cond-expr; update-expr) {

body

}

do {

body

} while (cond-expr)

init-expr

while (cond-expr) {

body

update-expr

}

goto body_label;

while (cond-expr) {

body_label: body

}

Write a complete MIPS assembly language program which prompts the user to enter a positive integer

n and computes and displays the sum of the squares of the first n positive integers. For example, if n is 6 the program

shall compute and display 1^2 + 2^2 +

3 ^2 + 4^2 + 5^2 + 6^2

. Here is the pseudocode for the program,

Program hw04-03

Function main()

Integer i, n, sum

PrintString("Enter an integer (> 0): ")

n = ReadInt()

For (i = 1, sum = 0; i <= n; ++i)

sum += i * i

End For

PrintString("The sum of the squares of the first ")

PrintInt(n)

PrintString(" positive integers is ")

PrintInt(sum)

Exit()

End Function main

End Program hw04-3