The Java statements (that you learned in CS171) to insert the list element at the start of the list are:
/* ======================================================== Statements to insert list element "ptr" at start of list ======================================================== */ ptr.next = head; // Make ptr.next points to first element of list head = ptr; // Make head points to the new list element |
The result of these statements is:
How to run the program:
|
|
I will show you the assembler program below.
But before I do so, I want to make sure that you realize:
|
I will assume that the list has been defined and I will only show you the assembler code to insert a new list element into an existing list.
ptr.next = head; head = ptr; |
is as follows:
main: /* ------------------------------------- ptr.next = head; -------------------------------------- */ // Get the value in the RHS movw r0, #:lower16:head movt r0, #:upper16:head // r0 = addr(head) ldr r0, [r0] // r0 = head // Get the ADDRESS of the LHS movw r1, #:lower16:ptr movt r1, #:upper16:ptr // r1 = addr(ptr) ldr r1, [r1] // r1 = ptr // Note: Addr(ptr.next) = r1+4, use base+offset mode !! // Store the RHS in the addr of LHS str r0, [r1, #4] // Update variable in memory !! /* ------------------------------------- head = ptr; -------------------------------------- */ // Get the value in the RHS movw r0, #:lower16:ptr movt r0, #:upper16:ptr // r0 = addr(ptr) ldr r0, [r0] // r0 = ptr // Get the ADDRESS of the LHS movw r1, #:lower16:head movt r1, #:upper16:head // r1 = addr(head) // Store the RHS in the addr of LHS str r0, [r1] // Update variable in memory !! |
How to run the program:
|