Question: in the Hmmm assembler: In this exercise, you are to write a function that computes the sum of integers from 1^2 through n^2. Within the

in the Hmmm assembler:

In this exercise, you are to write a function that computes the sum of integers from 1^2 through n^2. Within the sum function, youd have to call another function square which you will write. The main reason to have the function sum to call another function (both are relatively simple) is to force you to think about and implement mechanisms that save some register values such as the function return address and other registers that have to be saved in between function calls.

When completed successfully, the behavior of your program should look similar to the following.

$ hmmmAssembler.py -f hw6pr4.hmmm ... message of successful compilation ... $ hmmmSimulator.py Enter debugging mode? n Enter number: 4 30 $ hmmmSimulator.py Enter debugging mode? n Enter number: 5 55 $ hmmmSimulator.py Enter debugging mode? n Enter number: 10 385 $ hmmmSimulator.py Enter debugging mode? n Enter number: 6 91 

Because of the limited flexibility of Hmmm programming in line numbering, you probably should write you main program first, followed by the sum function, then the square function. The main program should read an integer, n. It then calls the function sum to compute 1^2 + 2^2 + + n^2. Finally the main program should print out the result.

Your sum function should just loop 1 through n, inclusive, where n is the given parameter. At each step of the loop, call another small function square which simply computes and returns the value of k * k where kis the given parameter, i.e., the current loop index. When the loop is completed, return the result through a register to the main program.

Before programming, you need to think through how you may use the registers. For example, which register is used to store n, which for result. In addition, when making function calls, you will have to save the return address register (the one you use for calln rx, n), and any registers that may be changed in the function. Write down as a section of comments in your main program for register use. Also do the same within the function sum. The function square is a leaf function, so it doesnt have to save the return address.

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!