The solution should be in assembly language not in C++. Here is an example of as
ID: 3768451 • Letter: T
Question
The solution should be in assembly language not in C++. Here is an example of assmebly language code. In this assignment, you are going to write an assembly language program to perform the following operation. Input a positive integer (say N), and then compute the sum as follows: Sum 1 + 3+5+ + N The user input will ALWAYS be a two-digit decimal number (between 01 and 99), You need NOT check the correctness of the input. For example, if the user input is "15" then your program will output "64" Hints You can use the following algorithm to compute the sum. int compute sum (int n) i = 1; sum-0 while (iExplanation / Answer
Assume Register 4 contains n, positive integer.
Put the output in Register 2.
Let Register 8 = sum
Register 9 =next odd number that we need to add
Register 10 = flag indicating whether all odd numbers up to n have been added
Begin: addi $8, $0, 0 #initialize sum to 0
addi $9, $0, 1 #set first odd number to add = 1
loop: slt $10, $4, $9 #check if the odd number is less than n
bne $10, $0, finish #if odd number is greater than n then exit
add $8, $8, $9 #update sum
addi $9, $9, 2 #get next odd number
j loop #repeat the summing process
finish: add $2, $8, $0 #put sum in output register