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

It is required that this program be written in ARM Assembly using raspberry pi. Submit an...
It is required that this program be written in ARM Assembly using raspberry pi. Submit an ARM assembly program that does the following: 1. Prompt for the user to enter a number (integer). 2. If the entered number is <100 print: "The input number is less than 100." 3. If the entered number is >=100 print: "The input number is greater than or equal to 100." 4. Prompt for the user to enter a single character. 5. If the entered...
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...
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...
How do you set up a Raspberry Pi 3 Model B as a master in an...
How do you set up a Raspberry Pi 3 Model B as a master in an I2C protocol? Please explain this process thoroughly, as well as the code you would use, if any
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...
Limit your answers to one paragraph or less. 1. Explain the difference between a statically allocated...
Limit your answers to one paragraph or less. 1. Explain the difference between a statically allocated array, a dynamically allocated array, and a linked list. 2. Linked lists have terrible performance for random access or searching of internal entries. Why? 3. Explain the advantages of adding a tail pointer to a linked list, and of doubly-linked over singlylinked lists.
Hi! I 'm writing a code for a doubly linked list and this is the header...
Hi! I 'm writing a code for a doubly linked list and this is the header file #include<iostream> #include <string> using namespace std; struct node { int data; node *next,*prev; node(int d,node *p=0,node *n=0) { data=d; prev=p; next=n; } }; class list { node *head,*tail; public: list(); bool is_empty(); int size(); void print(); void search(); int search2(int el); void add_last(int el); void add_first(int el); bool add_pos(); bool delete_first(); bool delete_last(); void delete_pos(int pos); void delete_el(); void add_sorted(); }; i want...
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.
You are given a singly linked list. Write a function to find if the linked list...
You are given a singly linked list. Write a function to find if the linked list contains a cycle or not. A linked list may contain a cycle anywhere. A cycle means that some nodes are connected in the linked list. It doesn't necessarily mean that all nodes in the linked list have to be connected in a cycle starting and ending at the head. You may want to examine Floyd's Cycle Detection algorithm. /*This function returns true if given...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT