Lab 4 Assignment W24 Solution

docx

School

University of Michigan *

*We aren’t endorsed by this school

Course

370

Subject

Computer Science

Date

Feb 20, 2024

Type

docx

Pages

5

Uploaded by AgentKookaburaPerson954

Report
Introduction to Computer Organization – Winter 2024 Lab 4 Solution Due: @11:55 PM, Wed February 14th The following assignment is intended to be completed during your assigned lab period. One member of your group must submit the assignment to Gradescope by the posted deadline and indicate your group members when submitting the assignment. Each group member must be present during the scheduled lab period in order to receive credit. Group names and uniqnames Pod Member Name Uniqname Staff eecs370staff For each of the following problems, one person should act as the "scribe" and log the discussions of the group. You should rotate who is the scribe for each problem and indicate in the given space.
Problem 1: Short Answer [10 points] Scribe: [Scribe's name here] 1. While waiting in office hours, you overhear your peer mention that, while they can work through caller-callee save register problems in the homework, they don't understand the motivation in the first place. In your own words (about 30 words or fewer), explain why saving/restoring register values with function calls is necessary, and what would happen if we didn't do it. There are a limited number of registers and these registers are shared between different function calls, so values need to be saved / restored to memory to ensure correctness. 2. The student thanks you for engaging in such wonderful peer instruction. They follow up with a question on linking, asking why accesses to global variables defined in a file (with no "extern" keyword used) need to be placed in the relocation table. They don't seem to really get what the relocation table is used for. Explain why this is needed, and a possible problem that might arise if we did not place such instructions in the table. After linking, each corresponding data/text/global sections are combined. This means that the original memory address of the global variable, even though defined in the same file, will likely be moved to a different memory location.
Problem 2: Link Like You’ve Never Linked Before! [20 Points] Scribe: [Scribe's name here] Read the following two files and fill in the rest of the symbol and relocation tables for each (on the next page). Note that not all entry spaces in the tables provided need to be used. We have completed one entry in each symbol and relocation table to show the format of each entry. Hint: see the Symbol and Relocation table guide on the website . main.c dog.c #include <string.h> #include <stdlib.h> #include <dog.h> #define DOG_CNT 500 // Hint: see link int tricks = 0; int pet(); extern int bark(int dog); extern int total_barks; extern int dog_happiness [500]; int main(){ for(int i = 0; i<DOG_CNT; i++){ dog_happiness[i] = 1; pet(i); } char out [50]; } void pet(int i){ static int petted_dogs = 0; dog_happiness[i] *= 2; petted_dogs += 1; if (rand() & 1) { bark(i); } } 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 #include <stdlib.h> extern int tricks; int total_barks = 10; void bark(int dog){ total_barks += 1; }
Your preview ends here
Eager to read complete document? Join bartleby learn and gain access to the full version
  • Access to all documents
  • Unlimited textbook solutions
  • 24/7 expert homework help
main.o symbol table dog.o symbol table Symbol Type (T/D/U) Symbol Type (T/D/U) tricks D tricks U pet T total_barks D bark U bark T total_barks U dog_happiness U main T rand U static petted_dogs D main.o relocation table dog.o relocation table Line Instruction (LD, ST, BL) Symbol Line Instruction (LD, ST, BL) Symbol 16 STUR dog_happiness 11 STUR total_barks 17 BL pet 11 LDUR total_barks 26 STUR dog_happiness 26 LDUR dog_happiness 27 STUR petted_dogs 27 LDUR petted_dogs 29 BL rand 30 BL bark Entries in blue are not required. Statics don’t have to be in the symbol table, but if they are they must be explicitly marked as static to avoid global naming conflicts. BLs to functions in the same file don’t need to be relocated if the branches in the ISA jump to PC-relative offsets, like beq in LC2K or BL in ARM. jalr would be an example of a branch that uses an absolute address. Underline indicates extern symbols that are unused; the corresponding symbol table entries may or may not be included (depending on the implementation of symbol table). Since there is no clear definition, no points are taken if not included.
Problem 3: The Best of the Tests [20 points, Autograded ] With project 2a right around the corner, let’s get ahead and find some of those buggy instructor solutions! For this problem, your group will be submitting (to autograder.io) assembly code AND its correct output object file when run through the project 2a assembler. Once you have written test cases that expose the bugs, you must write the corresponding correct object file output and submit it to the autograder for full credit. For every bug that is caught, you will receive 5 points. So for full credit, you need to catch 3 bugs with your tests, and provide the correct output for each. In addition to the constraints listed in the project, each LC2K program you write must be limited to 4 lines or fewer. No test cases should cause errors on a correct assembler. Each submission will be limited to 3 test cases, but fewer may be needed. Each output file name must be the same as the assembly, with the extension changed to .obj. You are free to resubmit tests you wrote for P1a, and you may submit these for P2a as well without honor code penalty (as long as they were written by members within your group or provided in course materials). You are encouraged to use (and submit) these test cases if you are still working on P2a. A great strategy is to run these test cases on your assembler and "diff" your output with the correct output any time you make a change. [Autograded]