Answered step by step
Verified Expert Solution
Question
1 Approved Answer
main.S Notes ( ARM version: see main.S ) - PA 8 This is the ARM 3 2 version of Cmain.c . Tasks are as follows:
main.S Notes ARM version: see main.S PA
This is the ARM version of Cmain.c Tasks are as follows:
You will need to finish the design of the stack frame and calculate the stack variables offsets as shown in the lecture. Use the local variables as defined in Cmain.c starter code to guide your design. You may add additional variables to the stack. If you use the registers carefully, additional stack space will not be needed.
In the starter code we have saved on the stack for you. Be aware that this is an odd number of registers and you may need to adjust the size of the pad to make sure the entire size of the stack frame is evenly divisible by byte aligned depending on the number of variables you place on the stack. Also keep the two buffers inbuf and bookbufbyte aligned. Here is a sample stack frame based on Cmain.c to get you started.
Figure out how you are going to use the preserved registers in your code by filling out the preserved register use table comment section. This documents your use and is helpful when writing your code.
Call setup setup is passed four arguments, using registers rr Argc r and argv are input parameters and funcr and fpbook r are both output parameters. It is important to note that the first two arguments to setup are argc in ro and arg in r So all you have to do is pass a pointer to a stack variable func in register and a pointer to the stack variable fpbook in register r Setup will write to both these stack locations.
If setup failed returns RETRNFAIL you will need to exit the program with EXITFAILURE. Make sure you branch to the exit code located at the bottom of the main function. In assembly language programming, all stack frame deallocation and function returns are done only at one place, and are located near the bottom of the function this differs from high level programming Do not forget that on setup failure, the bookfile is not open and the two stack variables func and fpbook will both contain NULL so do not call fclosefdbook in this case.
Prepare all the registers prior to the loop. You may want to store as many of the most referenced stack variables in preserved registers to avoid reading the stack all the time.
Main IO loop is the same as in Cmain.c If there is an error, branch to the exit code at the bottom of the function. Be aware that when calling rdbuf it has parameters, so the last one is on the stack.
There should be two branch targets near the end of mainbelow the loop for calling fprintf with either.Lrdmess or Lwrmess. It is possible to have both targets share the same code section to make the call to fprintf
Part of the code at the bottom of mainbelow the loop calls fclosefpbook Be aware that there should be a branch target for setup failure that should not call fclose as this may cause a segfault.
Make sure to return EXITFAILURE or exitSUCCESS as appropriate when main returns.
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started