Answered step by step
Verified Expert Solution
Link Copied!

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)- PA8
This is the ARM32 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 4-r10 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 8(8-byte aligned) depending on the number of variables you place on the stack. Also keep the two buffers (inbuf and bookbuf)8-byte 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 r0-r3. Argc (r0) and **argv (r1) are input parameters and **func()(r2) and **fpbook (r3) are both output parameters. It is important to note that the first two arguments to setup() are argc (in ro) and arg (in r1). So all you have to do is pass a pointer to a stack variable *func) in register r2 and a pointer to the stack variable *fpbook in register r3. Setup will write to both these stack locations.
If setup() failed (returns RETRN_FAIL), you will need to exit the program with EXIT_FAILURE. 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 fclose(fdbook) in this case.
Prepare all the registers prior to the 1O 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 I/O 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 5 parameters, so the last one is on the stack.
There should be two branch targets near the end of main()(below the 1O 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 main()(below the ??O loop) calls fclose(fpbook). Be aware that there should be a branch target for setup () failure that should not call fclose 0 as this may cause a segfault.
Make sure to return EXIT_FAILURE or exit_SUCCESS as appropriate when main() returns.
image text in transcribed

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access with AI-Powered Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Students also viewed these Databases questions