How to write MIPS function that recursively prints out linked list that takes one argument (address of firstNode), and is separated by commas.
.Ltext0: .section .rodata .align 8
.LC0: 0000 0A20456E .string "\n Enter the data for the nodes of singly linked list please: " 74657220 74686520 64617461 20666F72
.LC1: 003e 256400 .string "%d" .text .globl main main:
.LFB0:
.cfi_startproc 0000 55 pushq %rbp .cfi_def_cfa_offset 16 .cfi_offset 6, -16 0001 4889E5 movq %rsp, %rbp .cfi_def_cfa_register 6 0004 4883EC20 subq $32, %rsp
0008 BF100000 movl $16, %edi 00 000d E8000000 call malloc 00 0012 488945F8 movq %rax, -8(%rbp)
0016 488B45F8 movq -8(%rbp), %rax 001a 48C74008 movq $0, 8(%rax) 00000000
0022 BF000000 movl $.LC0, %edi 00 0027 B8000000 movl $0, %eax 00 002c E8000000 call printf 00
0031 488D45EC leaq -20(%rbp), %rax 0035 4889C6 movq %rax, %rsi 0038 BF000000 movl $.LC1, %edi 00 003d B8000000 movl $0, %eax 00 0042 E8000000 call __isoc99_scanf 00
0047 8B55EC movl -20(%rbp), %edx 004a 488B45F8 movq -8(%rbp), %rax 004e 8910 movl %edx, (%rax)
0050 488B45F8 movq -8(%rbp), %rax 0054 488945F0 movq %rax, -16(%rbp)
0058 48837DF0 cmpq $0, -16(%rbp) 00 005d 741B je .L2
005f EB0C jmp .L3
.L4:
0061 488B45F0 movq -16(%rbp), %rax 0065 488B4008 movq 8(%rax), %rax 0069 488945F0 movq %rax, -16(%rbp)
.L3:
006d 488B45F0 movq -16(%rbp), %rax 0071 488B4008 movq 8(%rax), %rax 0075 4885C0 testq %rax, %rax 0078 75E7 jne .L4
.L2:
007a B8000000 movl $0, %eax 00
007f C9 leave .cfi_def_cfa 7, 8 0080 C3 ret .cfi_endproc
.LFE0:
.Letext0:
// the same code is written in C language as well - just for better understanding
//#include <iostream.h>
#include <stdio.h>
#include <stdlib.h>
//#include <string.h>
// #include <conio.h>
#include <malloc.h>
/* I need to construct a dynamically singly linked
list using Mips Assembly. I would like for the user
to be able to enter integer values for each node and
the program allocate memory and assign the value
to the next node in the linked list. Could someone
show me how this would be done with lots of
comments so I understand what exactly is going on?
Thanks!
*/
// what we have just done below?
// declared a structure tag called vertex ( vertex = node in a
linked list)
// the connection between nodes are vertices ( = plural of vertex)
are done by arcs, links, or edges
// int data is simply a data of type integer - a variable to store
actual key value of every node or vertex
// the tricky and challenging line to understan is:
// struct vertex *nextPtr;
// we have made the recursive declaration for the data type struct
( = structure)
// which means the nextPtr ( = next Pointer) is again a variable of
type structure tag vertex
// hence the concept of linked list will happen
struct vertex {
int data;
struct vertex *nextPtr;
};
/*
typedef struct vertex VERTEX;
VERTEX *headNode, *firstNode, *tempNode = 0;
int counter = 0;
int option = 1;
firstNode = 0;
*/
// VERTEX = node in a tree or a graph and also in our singly linked
list
int main()
{
/*
while (option) {
headNode = (VERTEX *) malloc ( sizeof(VERTEX)):
// allocate the memory = malloc for the size of the
node
} // end while
*/
// time to create the first vertex or node of our list
struct vertex *rootNode;
// the root node must point at the begining or head of the
struct tag vertex
rootNode = (struct vertex *) malloc ( sizeof ( struct vertex));
// at the begining the next will point to the ground = null,
later when new nodes are added, the next pointer will get
updated
rootNode->nextPtr = 0;
// now let us get the data from the user and put them as node value
for each node
int data;
printf("\n Enter the data for the nodes of singly linked list
please: ");
scanf("%d", &data);
rootNode->data = data;
// now we have to update the next pointer
// other wise the link may look broken
// hence we need a temperory (temp) tracker node
struct vertex *tempTrackerNode;
// this will keep track where we are exactly in the linked
list
// for example if we had entered 100 data, the temp Tracker Node
may point to node 45 when we are at node 45
// it will point to node 46 when we traverse to the right
once
// unfortunately we can only travel ( traverse) in one direction as
it is not a doubly linked list
// it is just a very basic singly linked list
// there are great stalwarts (Heroes) like circular linked
lists
// which are much more powerful and intersting than the primitive
singly linkedlists!!
// any way, back to the question, ......
// we have declared the tracker node
// now point it to the root in the list
tempTrackerNode = rootNode;
if ( tempTrackerNode != 0 ) // the list is not empty
while ( tempTrackerNode -> nextPtr != 0 ) // while
the list is not empty, keep looping
tempTrackerNode = tempTrackerNode
-> nextPtr;
// end while
// end if
return 0; // exit
} // end of main()
How to write MIPS function that recursively prints out linked list that takes one argument (address...
Write a function searchList that recursively searches a linked list for a specified value. The function should return a pointer to the value if it’s found; otherwise, NULL should be returned. Use your function in a test program that creates a list of integers. The program should prompt the user for a value to locate in the list. It's a C program.
In c++, write a function that prints every other element in a linked list. Assume that it is a member function of a doubly linked list. This means you will need to use pointer operations.
Write a function that takes a list as an argument and returns true if the list is already sorted in increasing order. (You should not sort the list, and make sure that you just iterate over the list once! Only one loop!) WRITE THE CODE IN PYTHON
C++ 9) Write a recursive function printAll that takes an int num argument and prints all the numbers in the range [num, 0]. The function returns nothing. e.g. printAll(5) prints 5, 4, 3, 2, 1, 0. Call your function in the main
C++ ONLY Write a function calculator that takes two floating numbers and one operator and prints out the answer based on arithmetic. Assume that there are no overflow, underflow and division by zero cases. Your function should be named calculator Your function takes three input parameter: two double numbers and one char operator Your function does not return anything Your function prints answer in the format specified below Your function should set precision point to 2 Note: You must use...
C# please Write method to search a node in linked list using ID recursively, Write method to search a node in linked list using NAME recursively
Assume entries in a linked list are of type struct listrec: struct listrec { char value; struct listrec *next; }; Write a main() routine in which you create the following linked list: | a | --|----> | c | --|-----> | w | --|----> NULL Write a function called printlist that takes a pointer to the start of a linked list and prints out all the nodes in the list in sequence. The inferface of this function...
Write a function maxList that takes in a list of integers as argument and returns their highest. You may not use the max() or the sorted() Python built-in functions.
Write a function that takes, as an argument, a list of positive integers and a target value, and returns the number of times that the target value appears in the list. Call this function problem1(myList, target). For example, >>>problem1([1,2,3,4,5,6,5,4,3], 5) should return 2, and >>>problem1([1,2,3,4,5,6,5,4,3], 7) should return 0.
in python Part I: Sum of Odd Integers Write a recursive function sum-odds that takes a non-empty list of integers as an argument and returns the sum of only the odd integers in the list. In class we explored a recursive function called rsum that recursively computes the sum of a list of integers use it as a model to get started. Your function must be recursive and must not use any loops