Question: This program is about stack frames. This program has two functions: main ( ) and Add 5 Subtract 1 ( ) . Both functions will

This program is about stack frames. This program has two functions: main() and Add5Subtract1(). Both functions will setup and use a stack frame for local storage and passing parameters, as needed. (That includes the location that you will scanf the input into!)
main() will allocate space on the stack for 6 integers. Then it will prompt the user to enter each of 6 integers. If the first one is Zero, then exit the program. Hint: These will be accessed use Index plus Displacement addressing mode using the FP as the index register (aka FP relative)!
Once all 6 integers have been entered, then setup and call printf with the following format string:
print6: .string "Now calling:\tAdd5Subtract1(%d,%d,%d,%d,%d,%d );
"
There are 7 parameters. R0 is the address of the formatting string. The first 3 parameters are in registers. The last 3 are on the stack. To make this call, you need to allocate space for those 3 parameters on the stack. Those newly allocated locations will be accessed SP relative. The input parameters from the scanf's will be accessed FP relative. Clean up the stack (Deallocated those 3 words) as soon as the printf returns.
After the printf is completed, setup and call a function named Add5Subtract1. Same process as above...different number of parameters. Don't forget the Comment Block! Create this function to Add the first five parameters, then subtract the last. Return that value. It just does math, it does NOT print the results. Leave print the result to main().
Hints:
main() will start out with space for 8 values on the stack.2 to setup the stack frame (STMDB) and Plus 6 more (SUB #6<<2) to hold the inputs. Other than the LR, no protected registers are used in this assignment. The 6 input locations will be accessed FP relative. Then when you get ready to call printf you will allocate more space on the stack for parameters. Those locations are accessed SP relative.Release that memory after printf finished.
Then setup the stack for the call to Add5Subtract1.Release that memory after Add5Subtract1 finished. Use printf to print the results in main.
This assignment had 4 parts:
create main(). This function requires a stack frame. It will get the 6 parameters from the user
Arrange the format string address and those values into the 4 registers and three on the stack and make the call to printf. Note that R0, the first parameter, holds the address of the format string.).
Then arrange those values into the 4 registers and two on the stack and make the call to a function called: Add5Subtract1. In main(), print the results returned.
Create a function call Add5Subtract1 that added the first 5 parameters and subtracted the 6th. This function requires a stack frame.
Sample output:
Howard Miller CIST 039
Enter the 1st integer (0 to exit): 1
Enter the 2nd integer: 2
Enter the 3rd integer: 3
Enter the 4th integer: 4
Enter the 5th integer: 5
Enter the 6th integer: 6
Now calling: Add5Subtract1(1,2,3,4,5,6);
The result is: 9
Enter the 1st integer (0 to exit): -1
Enter the 2nd integer: -2
Enter the 3rd integer: -3
Enter the 4th integer: -4
Enter the 5th integer: -5
Enter the 6th integer: 14
Now calling: Add5Subtract1(-1,-2,-3,-4,-5,14);
The result is: -29
Enter the 1st integer (0 to exit): 0
------------------
(program exited with code: 0)
Press return to continue
Extra credit:
Do this assignment with single precision floating point numbers. Hint: printf can only print double precision, so you will need to convert each single to a double! Then put LOT of parameters for printf on the stack. But Add5Subtract1 should accept and do math as single precision.

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 Programming Questions!