Section 12.15 - CSE 230_ Computer Organization & Assembly Language _ zyBooks

pdf

School

Arizona State University, Tempe *

*We aren’t endorsed by this school

Course

230

Subject

Computer Science

Date

Feb 20, 2024

Type

pdf

Pages

19

Uploaded by MinisterRat3615

Report
2/15/24, 1:06 AM Section 12.15 - CSE 230: Computer Organization & Assembly Language | zyBooks https://learn.zybooks.com/zybook/2024Spring-T-CSE230-21671/chapter/12/section/15 1/19 Students: This content is controlled by your instructor, and is not zyBooks content. Direct questions or concerns about this content to your instructor. If you have any technical issues with the zyLab submission system, use the Trouble with lab button at the bottom of the lab. Students: Section 12.15 is a part of 1 assignment: Zylab 4 - Nested Procedure Call Includes: zyLab 12.15 Zylab 4 - Nested Procedure Call Write a MIPS program to add a given node in a linked list at the speci±ed location, using Nested Procedure Calls. If your code runs perfectly, but you didn't use Procedure Execution correctly, you will be given zero points. Given Inputs: the head of a linked list, i.e, address of the start (±rst node) of the list location: number of node in the linked list after which node is to be added (0 to add before the 1st node, 1 to add after 1st node and so on.) the address of the node to be inserted And each node contains: an integer value address to the next node (address is NULL (0) if it is the last node in the list) Write the following three functions that will be called in order to update the linked list by adding the new node. main task: calls the addNode function and reads the value of the newly added node. addNode inputs: head of linked list ( head), location to add node (n) and address of node to be added ( node)
2/15/24, 1:06 AM Section 12.15 - CSE 230: Computer Organization & Assembly Language | zyBooks https://learn.zybooks.com/zybook/2024Spring-T-CSE230-21671/chapter/12/section/15 2/19 task: calls the ±ndNode function and add the node after the n^th node in the linked list. If the number is greater than the size of list, then add the node at the end of the list. output: value of the inserted node. ±ndNode inputs: head of linked list (*head) and location to add node (n) task: navigate the linked list to ±nd the addresses of the n^th and (n+1)^th nodes outputs: addresses of the n^th and (n+1)^th nodes. Following is a sample C code segment to perform the required task. (this code is incomplete and does not include creating the linked list or a new node, so you cannot compile it using any C compiler.) You may modify the code for the functions, but the task performed should not be changed. // Parameters of a node in the linked list (need not declare or initialize in MIPS) typedef struct node { int value; // Value in the node accessed by node->value node* next; // Address of next node accessed by node->next } node; // Datatype for each node node *head; // address of head (first node) of linked list (global pointer) int main() { // Variable Declaration node *newNode; // address of node to be added int n; // number of the node in the list after which node is to be added int value; // Value of the node to be added // Task of main function value = addNode(head, n, newNode); } int addNode (node* head, int n, node* newNode) { node *addr1, *addr2; // addr1 = address of n^th node, addr2 = address of (n+1)^th node
2/15/24, 1:06 AM Section 12.15 - CSE 230: Computer Organization & Assembly Language | zyBooks https://learn.zybooks.com/zybook/2024Spring-T-CSE230-21671/chapter/12/section/15 3/19 if (n == 0) { // If node should be added at the beginning of the list newNode->next = head; // Next for new node = head of original list head = newNode; // global head updated to the new node return(newNode->value); // value of the node = data at the address of the node, and then return to caller } [addr1, addr2] = findNode (head, n); // Call findNode function addr1->next = newNode; // Next for n^th node = node to be added newNode->next = addr2; // Next for added node = (n+1)^th node of original list return(newNode->value); // value of the node = data at the address of the node } node* findNode (node* head, int n) { node* curr = head; // Start with head of linked list for (int i = 1; i < n; i ++) { curr = curr->next; // Update the pointer to next node address if (curr->next == 0) // Break if end of List break; } return([curr, curr->next]); // Two return values (need not return as array in MIPS) } Registers Variables $s0 head $s1 newNode $s2 n
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
2/15/24, 1:06 AM Section 12.15 - CSE 230: Computer Organization & Assembly Language | zyBooks https://learn.zybooks.com/zybook/2024Spring-T-CSE230-21671/chapter/12/section/15 4/19 Registers Variables $s3 val Linked List and New Node in Memory: Addresses Contents newNode newNode->value head node1->value head + 4 node1->next node1->next node2->value node1->next + 4 node2->next node2->next node3->value node2->next + 4 node3->next Example Test: If the values of $s0 through $s3 and Memory contents are initialized in the simulator as: (Use the '+' button under the Registers display to initialize register values for $s0, $s1, $s2 and the '+' button under the Memory display to initialize the initial array elements.) Registers Data $s0 4000 $s1 8000
2/15/24, 1:06 AM Section 12.15 - CSE 230: Computer Organization & Assembly Language | zyBooks https://learn.zybooks.com/zybook/2024Spring-T-CSE230-21671/chapter/12/section/15 5/19 Registers Data $s2 2 $s3 0 Addresses Contents 8000 230 4000 4 4004 3848 3848 -15 3852 6104 6104 -10 6108 5008 5008 0 5012 4500 4500 40 4504 0 The resultant registers are: Registers Data $s0 4000
2/15/24, 1:06 AM Section 12.15 - CSE 230: Computer Organization & Assembly Language | zyBooks https://learn.zybooks.com/zybook/2024Spring-T-CSE230-21671/chapter/12/section/15 6/19 Registers Data $s1 8000 $s2 2 $s3 230 The resultant array is: Addresses Contents 8000 230 8004 6104 4000 4 4004 3848 3848 -15 3852 8000 6104 -10 6108 5008 5008 0 5012 4500 4500 40 4504 0
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
2/15/24, 1:06 AM Section 12.15 - CSE 230: Computer Organization & Assembly Language | zyBooks https://learn.zybooks.com/zybook/2024Spring-T-CSE230-21671/chapter/12/section/15 7/19 Grading: Manual score (1 points) will be added after the deadline. 1. 4 automated tests each worth 1 point. The registers $s0, $s1, $s2, $s3 and the linked list elements in memory will be checked by the automated tests. 2. Comments specifying your choice of registers and each line of your code (0.5 points). 3. Correct use of Nested Procedure Calls (0.5 points). Submission Attempts: You will have limited number of submissions (5), i.e., only 5 attempts to compare with the automated tests, but you can run the simulator any number of times without clicking on submit for grading. 543330.2714138.qx3zqy7 LAB ACTIVITY 12.15.1: Zylab 4 - Nested Procedure Call 0 / 5 Load default template... ENTER SIMULATION STEP RUN Assembly # main function: setup and call addNo main: # Save registers on the stack move $ a0 , $ s0 # $ s0 has move $ a1 , $ s2 # $ s2 has move $ a2 , $ s1 # $ s1 has # Prepare the stack for the funct addi $ sp , $ sp , -12 # Allocate sw $ ra , 0( $ sp ) # Save ret sw $ a0 , 4( $ sp ) # Save hea Registers $s0 4000 $s1 8000 $s2 2 $s3 0 + Memory 3848 -15 3852 6104 4000 4 4004 3848 4500 40 4504 0 5008 0 5012 4500 6104 -10 6108 5008 8000 230 + Line 1 Line 2 Line 3 Line 4 Line 5 Line 6 Line 7 Line 8 Line 9 Line 10 Line 11 Line 12 Line 13 Line 14
2/15/24, 1:06 AM Section 12.15 - CSE 230: Computer Organization & Assembly Language | zyBooks https://learn.zybooks.com/zybook/2024Spring-T-CSE230-21671/chapter/12/section/15 8/19 3 submissions left Coding trail of your work 2/10 S ------------------------------ T ---------------------0---- Latest submission - 2:34 AM MST on 02/14/24 Total score: 0 / 5 Only show failing tests 1:Compare storage 0 / 1 al storage $s0 4000 $s1 8000 $s2 2 $s3 0 4000 4 4004 3848 3848 -15 Resulting storage Yours Registers $s0 4000 $s1 8000 $s2 2 $s3 230 $a0 0 $a1 0 $a2 8000 Graded Yours Registers $s0 4000 $s1 8000 $s2 2 $s3 230 Memory 3848 -15 3852 6104 4000 4 More options Submit for grading What is this? Download this submission
2/15/24, 1:06 AM Section 12.15 - CSE 230: Computer Organization & Assembly Language | zyBooks https://learn.zybooks.com/zybook/2024Spring-T-CSE230-21671/chapter/12/section/15 9/19 3852 6104 6104 -10 6108 5008 5008 0 5012 4500 4500 40 4504 0 8000 230 $ra 52 $sp 2147483188 $t0 8000 $zero 0 Memory 3848 -15 3852 6104 4000 4 4004 3848 4500 40 4504 0 5008 0 5012 4500 6104 -10 6108 5008 8000 230 8004 8000 0 8000 2147483176 0 2147483180 0 2147483184 8000 4004 3848 4500 40 4504 0 5008 0 5012 4500 6104 -10 6108 5008 8000 230 8004 8000 2:Compare storage 0 / 1 l storage Resulting storage
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
2/15/24, 1:06 AM Section 12.15 - CSE 230: Computer Organization & Assembly Language | zyBooks https://learn.zybooks.com/zybook/2024Spring-T-CSE230-21671/chapter/12/section/15 10/19 s0 13804 s1 4000 s2 0 s3 0 804 -8 808 8000 000 80 004 0 000 -230 Yours Registers $s0 13804 $s1 4000 $s2 0 $s3 230 $a0 0 $a1 0 $a2 4000 $ra 52 $sp 2147483188 $t0 4000 $zero 0 Memory 13804 -8 13808 8000 4000 -230 4004 4000 8000 80 8004 0 0 4000 2147483176 0 2147483180 0 Graded Yours Registers $s0 13804 $s1 4000 $s2 0 $s3 230 Memory 13804 -8 13808 8000 4000 -230 4004 4000 8000 80 8004 0
2/15/24, 1:06 AM Section 12.15 - CSE 230: Computer Organization & Assembly Language | zyBooks https://learn.zybooks.com/zybook/2024Spring-T-CSE230-21671/chapter/12/section/15 11/19 2147483184 4000 3:Compare storage 0 / 1 l storage s0 8016 s1 13000 s2 100 s3 0 016 -50 020 8040 024 100 028 6032 032 -80 036 0 040 -100 044 4024 000 0 Resulting storage Yours Registers $s0 8016 $s1 13000 $s2 100 $s3 230 $a0 0 $a1 0 $a2 13000 $ra 52 $sp 2147483188 $t0 13000 $zero 0 Memory 13000 0 13004 13000 4024 100 4028 6032 6032 -80 6036 0 Graded Yours Registers $s0 8016 $s1 13000 $s2 100 $s3 230 Memory 13000 0 13004 13000 4024 100 4028 6032 6032 -80 6036 0 8016 -50 8020 8040 8040 -100 8044 4024
2/15/24, 1:06 AM Section 12.15 - CSE 230: Computer Organization & Assembly Language | zyBooks https://learn.zybooks.com/zybook/2024Spring-T-CSE230-21671/chapter/12/section/15 12/19 8016 -50 8020 8040 8040 -100 8044 4024 0 13000 2147483176 0 2147483180 0 2147483184 13000 4:Compare storage 0 / 1 l storage s0 10000 s1 4024 s2 3 s3 0 000 23 004 5008 008 -5 012 8016 016 20 020 0 Resulting storage Yours Registers $s0 10000 $s1 4024 $s2 3 $s3 230 $a0 0 $a1 0 $a2 4024 $ra 52 $sp 2147483188 $t0 4024 Graded Yours Registers $s0 10000 $s1 4024 $s2 3 $s3 230 Memory 10000 23 10004 5008 4024 30 4028 4024 5008 -5 5012 8016
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
2/15/24, 1:06 AM Section 12.15 - CSE 230: Computer Organization & Assembly Language | zyBooks https://learn.zybooks.com/zybook/2024Spring-T-CSE230-21671/chapter/12/section/15 13/19 024 30 $zero 0 Memory 10000 23 10004 5008 4024 30 4028 4024 5008 -5 5012 8016 8016 20 8020 0 0 4024 2147483176 0 2147483180 0 2147483184 4024 8016 20 8020 0 5:Manual score 0 / 1 Nested Procedure Call and Comments Your instructor hasn't graded this test yet. Previous submissions 4:15 AM on 2/13/24 0 / 4 Hide
2/15/24, 1:06 AM Section 12.15 - CSE 230: Computer Organization & Assembly Language | zyBooks https://learn.zybooks.com/zybook/2024Spring-T-CSE230-21671/chapter/12/section/15 14/19 Only show failing tests 1:Compare storage 0 / 1 Initial storage Registers $s0 4000 $s1 8000 $s2 2 $s3 0 Memory 4000 4 Resulting storage Yours Registers $s0 4000 $s1 8000 $s2 2 $s3 0 $a0 0 Graded Yours Expected Registers $s0 4000 4000 $s1 8000 8000 $s2 2 2 $s3 0 230 Memory 3848 -15 -15 main.s # main function: setup and call addNode main: # Initialize the registers with the head of the list, location to add # Assume these values are provided and loaded into $a0 (head), $a1 (l # Call addNode function jal addNode # Additional code for program finish j Finish # addNode function: Adds a new node at the specified location # Arguments: $a0 = head of the list, $a1 = location, $a2 = address of the addNode: Download this submission 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
2/15/24, 1:06 AM Section 12.15 - CSE 230: Computer Organization & Assembly Language | zyBooks https://learn.zybooks.com/zybook/2024Spring-T-CSE230-21671/chapter/12/section/15 15/19 4004 3848 3848 -15 3852 6104 6104 -10 6108 5008 5008 0 5012 4500 4500 40 4504 0 8000 230 $a1 0 $a2 0 $ra 4 $t1 0 $zero 0 Memory 3848 -15 3852 6104 4000 4 4004 3848 4500 40 4504 0 5008 0 5012 4500 6104 -10 6108 5008 8000 230 0 0 4 0 3852 6104 8000 4000 4 4 4004 3848 3848 4500 40 40 4504 0 0 5008 0 0 5012 4500 4500 6104 -10 -10 6108 5008 5008 8000 230 230 8004 6104 2:Compare storage 0 / 1 Initial storage Resulting storage Yours Graded Yours Expected
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
2/15/24, 1:06 AM Section 12.15 - CSE 230: Computer Organization & Assembly Language | zyBooks https://learn.zybooks.com/zybook/2024Spring-T-CSE230-21671/chapter/12/section/15 16/19 gisters $s0 13804 $s1 4000 $s2 0 $s3 0 emory 13804 -8 13808 8000 8000 80 8004 0 4000 -230 Registers $s0 13804 $s1 4000 $s2 0 $s3 0 $a0 0 $a1 0 $a2 0 $ra 4 $t1 0 $zero 0 Memory 13804 -8 13808 8000 4000 -230 8000 80 8004 0 0 0 4 0 Registers $s0 13804 4000 $s1 4000 4000 $s2 0 0 $s3 0 -230 Memory 13804 -8 -8 13808 8000 8000 4000 -230 -230 8000 80 80 8004 0 0 4004 13804 3:Compare storage 0 / 1 Initial storage gisters $s0 8016 Resulting storage Yours Registers $s0 8016 Graded Yours Expected Registers $s0 8016 8016
2/15/24, 1:06 AM Section 12.15 - CSE 230: Computer Organization & Assembly Language | zyBooks https://learn.zybooks.com/zybook/2024Spring-T-CSE230-21671/chapter/12/section/15 17/19 $s1 13000 $s2 100 $s3 0 emory 8016 -50 8020 8040 4024 100 4028 6032 6032 -80 6036 0 8040 -100 8044 4024 13000 0 $s1 13000 $s2 100 $s3 0 $a0 0 $a1 0 $a2 0 $ra 4 $t1 0 $zero 0 Memory 13000 0 4024 100 4028 6032 6032 -80 6036 0 8016 -50 8020 8040 8040 -100 8044 4024 0 0 4 0 $s1 13000 13000 $s2 100 100 $s3 0 0 Memory 13000 0 0 4024 100 100 4028 6032 6032 6032 -80 -80 6036 0 13000 8016 -50 -50 8020 8040 8040 8040 -100 -100 8044 4024 4024 13004 0 4:Compare storage 0 / 1 Initial storage Resulting storage
2/15/24, 1:06 AM Section 12.15 - CSE 230: Computer Organization & Assembly Language | zyBooks https://learn.zybooks.com/zybook/2024Spring-T-CSE230-21671/chapter/12/section/15 18/19 gisters $s0 10000 $s1 4024 $s2 3 $s3 0 emory 10000 23 10004 5008 5008 -5 5012 8016 8016 20 8020 0 4024 30 Yours Registers $s0 10000 $s1 4024 $s2 3 $s3 0 $a0 0 $a1 0 $a2 0 $ra 4 $t1 0 $zero 0 Memory 10000 23 10004 5008 4024 30 5008 -5 5012 8016 8016 20 8020 0 0 0 4 0 Graded Yours Expected Registers $s0 10000 10000 $s1 4024 4024 $s2 3 3 $s3 0 30 Memory 10000 23 23 10004 5008 5008 4024 30 30 5008 -5 -5 5012 8016 8016 8016 20 20 8020 0 4024 4028 0 5:Manual score 0 / 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
2/15/24, 1:06 AM Section 12.15 - CSE 230: Computer Organization & Assembly Language | zyBooks https://learn.zybooks.com/zybook/2024Spring-T-CSE230-21671/chapter/12/section/15 19/19 Activity summary for assignment: Zylab 4 - Nested Procedure Call 0 % 0 % submitted to canvas Section 12 . 15 0 % Lab activities 12.15.1 0 % Nested Procedure Call and Comments Your instructor hasn't graded this test yet. Trouble with lab? Completion details