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 AddSubtract 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 integers. Then it will prompt the user to enter each of 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 integers have been entered, then setup and call printf with the following format string:
print: string Now calling:tAddSubtractdddddd ;
There are parameters. R is the address of the formatting string. The first parameters are in registers. The last are on the stack. To make this call, you need to allocate space for those 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 words as soon as the printf returns.
After the printf is completed, setup and call a function named AddSubtract 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 values on the stack. to setup the stack frame STMDB and Plus more SUB # to hold the inputs. Other than the LR no protected registers are used in this assignment. The 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 AddSubtractRelease that memory after AddSubtract finished. Use printf to print the results in main.
This assignment had parts:
create main This function requires a stack frame. It will get the parameters from the user
Arrange the format string address and those values into the registers and three on the stack and make the call to printf. Note that R the first parameter, holds the address of the format string.
Then arrange those values into the registers and two on the stack and make the call to a function called: AddSubtract In main print the results returned.
Create a function call AddSubtract that added the first parameters and subtracted the th This function requires a stack frame.
Sample output:
Howard Miller CIST
Enter the st integer to exit:
Enter the nd integer:
Enter the rd integer:
Enter the th integer:
Enter the th integer:
Enter the th integer:
Now calling: AddSubtract;
The result is:
Enter the st integer to exit:
Enter the nd integer:
Enter the rd integer:
Enter the th integer:
Enter the th integer:
Enter the th integer:
Now calling: AddSubtract;
The result is:
Enter the st integer to exit:
program exited with code:
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 AddSubtract 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
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
