Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Using ARM Assembly Emulator VisUAL found at (https://salmanarif.bitbucket.io/vis

ID: 3842400 • Letter: U

Question

Using ARM Assembly Emulator VisUAL found at (https://salmanarif.bitbucket.io/visual/downloads.html),

Please comment/explain each line of code.

Write a simple array exchange program in VisUAL that exchanges the values from one array to another:

1. Use the VisUAL ARM emulator tool
2. Define two arrays of 32-bit values, 3 entries in each array
3. Now, loop through the two arrays exchanging their values

ARM Statements used: mov, ldr, adr, sub, add, mov, cmp, b and beq ARM statements

So it should do the following:

Before the Exchange View Memory Contents Array Start address 0x100 End address: 0x1100 emory Map Byte 3 Byte 2 Byte 1 Byte e Word Address Word Valu 0x100 0x0 0x0 0x0 0x10 0x10 0x104 0x0 0x0 0x0 0x20 0x20 Array 2 0x108 0x30 0x0 0x0 0x0 0x30 0x10C 0x0 0x0 0x0 0x40 0x40 exe exe exe 0x110 0x50 0x50 0x114 0x0 0x0 0x0 0x60 0x60 Word Value Format D Hex Memory Map Key nstructions Data After the Exchange View Memory Contents Array 1. emory Map Start address: 0x100 End address: 0x1100 Byte 3 Byte 2 Byte 1 Byte e Word Address Word Valu 0x100 0x0 0x0 0x40 0x40 0x104. 0x0 0x0 0x0 0x50 0x50 0x60 0x108 0x60 Array 2 0x10C 0x10 0x10 exe exe 0x110 0x0 0x20 0x20 0x30 0x114 0x0 0x0 0x0 0x30 Word Value Format Dec Hex Memory Map Key nstructions Data

Explanation / Answer

Answer:

Assembly Language Code:

P1:
        push    rbp
        mov     rbp, rsp
        sub     rsp, 32
        mov     QWORD PTR [rbp-24], rdi
        mov     DWORD PTR [rbp-28], esi
        mov     DWORD PTR [rbp-4], 0
.L3:
        mov     eax, DWORD PTR [rbp-4]
        cmp     eax, DWORD PTR [rbp-28]
        jge     .L2
        mov     eax, DWORD PTR [rbp-4]
        cdqe
        lea     rdx, [0+rax*4]
        mov     rax, QWORD PTR [rbp-24]
        add     rax, rdx
        mov     eax, DWORD PTR [rax]
        mov     esi, eax
        mov     edi, OFFSET FLAT:std::cout
        call    std::basic_ostream<char, std::char_traits<char> >::operator<<(int)
        mov     esi, 32
        mov     rdi, rax
        call    std::basic_ostream<char, std::char_traits<char> >& std::operator<< <std::char_traits<char> >(std::basic_ostream<char, std::char_traits<char> >&, char)
        add     DWORD PTR [rbp-4], 1
        jmp     .L3
.L2:
        mov     esi, OFFSET FLAT:std::basic_ostream<char, std::char_traits<char> >& std::endl<char, std::char_traits<char> >(std::basic_ostream<char, std::char_traits<char> >&)
        mov     edi, OFFSET FLAT:std::cout
        call    std::basic_ostream<char, std::char_traits<char> >::operator<<(std::basic_ostream<char, std::char_traits<char> >& (*)(std::basic_ostream<char, std::char_traits<char> >&))
        nop
        leave
        ret
swapArrayElements(int*, int, int):
        push    rbp
        mov     rbp, rsp
        mov     QWORD PTR [rbp-24], rdi
        mov     DWORD PTR [rbp-28], esi
        mov     DWORD PTR [rbp-32], edx
        mov     DWORD PTR [rbp-4], 0
        mov     eax, DWORD PTR [rbp-28]
        cdqe
        lea     rdx, [0+rax*4]
        mov     rax, QWORD PTR [rbp-24]
        add     rax, rdx
        mov     eax, DWORD PTR [rax]
        mov     DWORD PTR [rbp-4], eax
        mov     eax, DWORD PTR [rbp-28]
        cdqe
        lea     rdx, [0+rax*4]
        mov     rax, QWORD PTR [rbp-24]
        add     rdx, rax
        mov     eax, DWORD PTR [rbp-32]
        cdqe
        lea     rcx, [0+rax*4]
        mov     rax, QWORD PTR [rbp-24]
        add     rax, rcx
        mov     eax, DWORD PTR [rax]
        mov     DWORD PTR [rdx], eax
        mov     eax, DWORD PTR [rbp-32]
        cdqe
        lea     rdx, [0+rax*4]
        mov     rax, QWORD PTR [rbp-24]
        add     rdx, rax
        mov     eax, DWORD PTR [rbp-4]
        mov     DWORD PTR [rdx], eax
        nop
        pop     rbp
        ret
.LC0:
        .string "The original array is: "
.LC1:
        .string "The swapped array is: "
main:
        push    rbp
        mov     rbp, rsp
        sub     rsp, 16
        mov     DWORD PTR [rbp-16], 6
        mov     DWORD PTR [rbp-12], 2
        mov     DWORD PTR [rbp-8], 5
        mov     DWORD PTR [rbp-4], 1
        mov     esi, OFFSET FLAT:.LC0
        mov     edi, OFFSET FLAT:std::cout
        call    std::basic_ostream<char, std::char_traits<char> >& std::operator<< <std::char_traits<char> >(std::basic_ostream<char, std::char_traits<char> >&, char const*)
        lea     rax, [rbp-16]
        mov     esi, 4
        mov     rdi, rax
        call    printArray(int*, int)
        lea     rax, [rbp-16]
        mov     edx, 3
        mov     esi, 0
        mov     rdi, rax
        call    swapArrayElements(int*, int, int)
        mov     esi, OFFSET FLAT:.LC1
        mov     edi, OFFSET FLAT:std::cout
        call    std::basic_ostream<char, std::char_traits<char> >& std::operator<< <std::char_traits<char> >(std::basic_ostream<char, std::char_traits<char> >&, char const*)
        lea     rax, [rbp-16]
        mov     esi, 4
        mov     rdi, rax
        call    printArray(int*, int)
        mov     eax, 0
        leave
        ret
__static_initialization_and_destruction_0(int, int):
        push    rbp
        mov     rbp, rsp
        sub     rsp, 16
        mov     DWORD PTR [rbp-4], edi
        mov     DWORD PTR [rbp-8], esi
        cmp     DWORD PTR [rbp-4], 1
        jne     .L9
        cmp     DWORD PTR [rbp-8], 65535
        jne     .L9
        mov     edi, OFFSET FLAT:std::__ioinit
        call    std::ios_base::Init::Init()
        mov     edx, OFFSET FLAT:__dso_handle
        mov     esi, OFFSET FLAT:std::__ioinit
        mov     edi, OFFSET FLAT:std::ios_base::Init::~Init()
        call    __cxa_atexit
.L9:
        nop
        leave
        ret
_GLOBAL__sub_I__Z10printArrayPii:
        push    rbp
        mov     rbp, rsp
        mov     esi, 65535
        mov     edi, 1
        call    __static_initialization_and_destruction_0(int, int)
        pop     rbp
        ret

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote