Question

In: Computer Science

Writing a statically allocated linked list in ARM assembly (raspberry pi). Step 1: You will statically...

Writing a statically allocated linked list in ARM assembly (raspberry pi).

Step 1: You will statically allocate some space for your link list elements. You need to make 5 elements, each elements should have two components, the next pointer first then the value stored. First initialize next pointer to NULL. The value stored at the address will be a string pointer.

Step 2: You will then write a function that links the statically allocated linked list elements together.

Step 3: In your main you call your linking function to link all 5 elements together.

Step 4: Print out each element in order by traversing the list. This means that you can't store each address in registers. You will lose points if you just print everything. Step 5: Use the malloc call to allocate for n (any number of entries represented by the letter n) entries from the command line.

Solutions

Expert Solution

Solution:

Given data:

Source Code:

extern malloc
extern free
extern putchar
extern puts

section .data
    size_i:             ; Used to determine the size of the structure
    struc node
        info: resd  1
        next: resd  1
    endstruc
    len: equ $ - size_i  ; Size of the data type

    nullMes:    db  'Null pointer - the list is empty', 0
    addMes:     db  'Adding a new element', 0
    printMes:   db  'Printing a linked list:', 0
    cleanMes:   db  'Cleaning an element', 0
    doneCleanMes:   db  'Ready for cleaning...', 0
    emptyListMes:    db  '- empty list -', 0

section .bss
    prim:   resd  1
append:
    push ebp            ; Save the stack
    mov ebp, esp

    push eax            ; Save the registers
    push ebx

    push len            ; Size to get from the heap and pass the size to the malloc function
    call malloc         ; Call the malloc function - now eax has the address of the allocated memory

    mov ebx, [ebp + 12]
    mov [eax + info], ebx    ; Add the element to the node data field
    mov dword [eax + next], 0   ; Address of the next element is NULL, because it is the last element in the list

    mov ebx, [ebp + 8]  ; Retrieve the address to the first element
    cmp dword [ebx], 0
    je null_pointer

    mov ebx, [ebx]      ; This parameter was the address of the address
                        ; Now it is the address of the first element, in this case, not null
    ; If it is not NULL, find the address of the last element
next_element:
    cmp dword [ebx + next], 0
    je found_last
    mov ebx, [ebx + next]
    jmp next_element

found_last:
    push eax
    push addMes
    call puts
    add esp, 4              ; Restore the stack
    pop eax

    mov [ebx + next], eax   ; Last element is this one from the newly allocated memory block

go_out:
    pop ebx             ; Restore registers
    pop eax

    mov esp, ebp
    pop ebp
    ret 8               ; Return to the caller function and cleaning the stack

null_pointer:
    push eax
    push nullMes
    call puts
    add esp, 4
    pop eax

    mov [ebx], eax      ; Point the address of the first element to the allocated memory

    jmp go_out
print:
    push ebp
    mov ebp, esp

    push ebx
    mov ebx, [ebp + 8]  ; Address of the first element
    cmp ebx, 0
    je emptyList

    push eax
    push printMes       ; Print message "Printing a linked list"
    call puts
    add esp, 4
    pop eax

Related Solutions

Writing a caesar cipher in ARM assembly. INSTRUCTIONS: Step 1: The first thing you should do...
Writing a caesar cipher in ARM assembly. INSTRUCTIONS: Step 1: The first thing you should do is modify the case conversion program String.s (provided) Instead of subtracting 32 from all numbers you want to add a constant number which we will call the key. Assume that all input will be lowercase. So it'll look like this, k = 2; letter = 'a'; newletter = k+letter; Above is pseudocode and ABOVE NOT ASSEMBLY CODE DO NOT COPY. Use bl puts to...
Make following changes. step(A) step 1 Implementation a Generic Linked List using the program developed in...
Make following changes. step(A) step 1 Implementation a Generic Linked List using the program developed in the class. step 2  Implement StackImpl class using the generic linked list. step 3 Test the program with different type and number of matching and un-matching brackets. This is how it works! When you run the class MatchBrackets a popup dialog appears asking you to select a file. You are provided two input files in the project. input1.txt contains matching brackets and input2.txt does not...
Can you make this singular linked list to doubly linked list Create a Doubly Linked List....
Can you make this singular linked list to doubly linked list Create a Doubly Linked List. Use this to create a Sorted Linked List, Use this to create a prioritized list by use. Bring to front those links recently queried. -----link.h------ #ifndef LINK_H #define LINK_H struct Link{ int data; Link *lnkNxt; }; #endif /* LINK_H */ ----main.cpp---- //System Level Libraries #include <iostream> //I/O Library using namespace std; //Libraries compiled under std #include"Link.h" //Global Constants - Science/Math Related //Conversions, Higher Dimensions...
I need a MIPS Assembly program that "Display the elements of the linked list in reverse...
I need a MIPS Assembly program that "Display the elements of the linked list in reverse order." It needs subprogram and those subprogram does not have t registers.
Please use C++ and linked list to solve this problem Linked list 1 -> 3 ->...
Please use C++ and linked list to solve this problem Linked list 1 -> 3 -> 4 -> 5-> 6 ->7 replaceNode( 5 , 6) // Replace 5 with 6     result 1 -> 3 -> 4 -> 6 -> 6 ->7 Base code #include <iostream> using namespace std; class Node { public:     int data;     Node *next;     Node(int da = 0, Node *p = NULL) {         this->data = da;         this->next = p;     } };...
Please use C++ and linked list to solve this problem Linked list 1 -> 2 ->...
Please use C++ and linked list to solve this problem Linked list 1 -> 2 -> 3 -> 4 -> 5-> 6 ->7 replaceNode( 5 , 6) // Replace 5 with 6     result 1 -> 2 -> 3 -> 4 -> 6 -> 6 ->7 Base code #include <iostream> using namespace std; class Node { public:     int data;     Node *next;     Node(int da = 0, Node *p = NULL) {         this->data = da;         this->next =...
In this homework, you will implement a single linked list to store a list of employees...
In this homework, you will implement a single linked list to store a list of employees in a company. Every employee has an ID, name, department, and salary. You will create 2 classes: Employee and EmployeeList. Employee class should have all information about an employee and also a “next” pointer. See below: Employee Type Attribute int ID string name string department int salary Employee* next Return Type Function (constructor) Employee(int ID, string name, string department, int salary) EmployeeList class should...
how do you add two matrices linked list in java? (am using linked list because 2D...
how do you add two matrices linked list in java? (am using linked list because 2D arrays are not allowed.) ex [1st matrix] 1 3 2 4 2 1 3 2 4 + [2nd matrix] 3 2 3 2 1 4 5 2 3 = [3rd matrix] 4 5 5 6 3 5 8 4 7
Linked List-Based Queue Sketches In this section you will sketch several linked list-based queues. Hint: Recall...
Linked List-Based Queue Sketches In this section you will sketch several linked list-based queues. Hint: Recall that a proper sketch of a linked list-based queue is just a series of boxes with elements inside. 2, 3, 4 Sketch the linked list-based queue that results from the following operations: Default constructor (create empty) Add(2) Add(3) Add(4) ? Replace this with your sketch Add and Remove Sketch the linked list-based queue that results from the following operations: Default constructor (create empty) Add(2)...
You have to write an ARM Assembly M4 program for SLTB004A Thunderboard Sense 2. Write an...
You have to write an ARM Assembly M4 program for SLTB004A Thunderboard Sense 2. Write an assembly program that blinks the red LED to send out a SOS Morse code (... --- ...). The dot duration must be 1/4 second and the dash one - 1/2 sec. Duration between dots and dashes is 1/4 second. After displaying SOS the program must delay for 2 seconds and then loop back to blink out SOS again. Use LETIMER for generating all time...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT