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

x86 Assembly(MASM) You program will ask the user to enter an integer saying, \"H

ID: 3802437 • Letter: X

Question

x86 Assembly(MASM)

You program will ask the user to enter an integer saying, "How many integer do you want to enter?" Once the user enters the number (count), you will prompt the user to enter integer repeatedly for that many times, saying, "Enter Integer Number 1" _ "Enter Integer Number 2"_ and so on. Once all the expected integer numbers are given, you will print the user-entered numbers in reverse order saying, "These are the numbers in reverse order: _____..." and then print the sum of the numbers saying, "The sum of the given numbers is: ______ ". You program will ask the user to enter a string. Once the user enters the string and presses enter, you program will read the string and count the number of words in that string. Then, your program will print the number of words found in that string. Output example: Your program: Enter your string: _ User: I like assembly-language programming. Your program: Your entered string had 4 words. Your program: Repeat (Y/N)?

Explanation / Answer

Answer:

1)

PrnItReverseSum Assembly Language Code :

.LC0:
        .string "Enter the num: "
.LC1:
        .string " Reverse of "
.LC2:
        .string " is: "
main:
        push    rbp
        mov     rbp, rsp
        sub     rsp, 16
        mov     DWORD PTR [rbp-4], 0
        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     rsi, rax
        mov     edi, OFFSET FLAT:std::cin
        call    std::basic_istream<char, std::char_traits<char> >::operator>>(int&)
        mov     eax, DWORD PTR [rbp-16]
        mov     DWORD PTR [rbp-8], eax
.L3:
        mov     eax, DWORD PTR [rbp-16]
        test    eax, eax
        jle     .L2
        mov     ecx, DWORD PTR [rbp-16]
        mov     edx, 1717986919
        mov     eax, ecx
        imul    edx
        sar     edx, 2
        mov     eax, ecx
        sar     eax, 31
        sub     edx, eax
        mov     eax, edx
        mov     DWORD PTR [rbp-12], eax
        mov     edx, DWORD PTR [rbp-12]
        mov     eax, edx
        sal     eax, 2
        add     eax, edx
        add     eax, eax
        sub     ecx, eax
        mov     eax, ecx
        mov     DWORD PTR [rbp-12], eax
        mov     edx, DWORD PTR [rbp-4]
        mov     eax, edx
        sal     eax, 2
        add     eax, edx
        add     eax, eax
        mov     edx, eax
        mov     eax, DWORD PTR [rbp-12]
        add     eax, edx
        mov     DWORD PTR [rbp-4], eax
        mov     ecx, DWORD PTR [rbp-16]
        mov     edx, 1717986919
        mov     eax, ecx
        imul    edx
        sar     edx, 2
        mov     eax, ecx
        sar     eax, 31
        sub     edx, eax
        mov     eax, edx
        mov     DWORD PTR [rbp-16], eax
        jmp     .L3
.L2:
        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*)
        mov     rdx, rax
        mov     eax, DWORD PTR [rbp-8]
        mov     esi, eax
        mov     rdi, rdx
        call    std::basic_ostream<char, std::char_traits<char> >::operator<<(int)
        mov     esi, OFFSET FLAT:.LC2
        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 const*)
        mov     rdx, rax
        mov     eax, DWORD PTR [rbp-4]
        mov     esi, eax
        mov     rdi, rdx
        call    std::basic_ostream<char, std::char_traits<char> >::operator<<(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     .L7
        cmp     DWORD PTR [rbp-8], 65535
        jne     .L7
        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
.L7:
        nop
        leave
        ret
_GLOBAL__sub_I_main:
        push    rbp
        mov     rbp, rsp
        mov     esi, 65535
        mov     edi, 1
        call    __static_initialization_and_destruction_0(int, int)
        pop     rbp
        ret

2)

CountWord Assembly Language Code :

countWords(char*):
        push    rbp
        mov     rbp, rsp
        mov     QWORD PTR [rbp-24], rdi
        mov     DWORD PTR [rbp-4], 0
        mov     DWORD PTR [rbp-8], 0
.L6:
        mov     rax, QWORD PTR [rbp-24]
        movzx   eax, BYTE PTR [rax]
        test    al, al
        je      .L2
        mov     rax, QWORD PTR [rbp-24]
        movzx   eax, BYTE PTR [rax]
        cmp     al, 32
        je      .L3
        mov     rax, QWORD PTR [rbp-24]
        movzx   eax, BYTE PTR [rax]
        cmp     al, 10
        je      .L3
        mov     rax, QWORD PTR [rbp-24]
        movzx   eax, BYTE PTR [rax]
        cmp     al, 9
        jne     .L4
.L3:
        mov     DWORD PTR [rbp-4], 0
        jmp     .L5
.L4:
        cmp     DWORD PTR [rbp-4], 0
        jne     .L5
        mov     DWORD PTR [rbp-4], 1
        add     DWORD PTR [rbp-8], 1
.L5:
        add     QWORD PTR [rbp-24], 1
        jmp     .L6
.L2:
        mov     eax, DWORD PTR [rbp-8]
        pop     rbp
        ret
.LC0:
        .string "No of words: %u "
main:
        push    rbp
        mov     rbp, rsp
        sub     rsp, 48
        movabs rax, 2337218072272006735
        mov     QWORD PTR [rbp-48], rax
        movabs rax, 2314885530818453536
        mov     QWORD PTR [rbp-40], rax
        movabs rax, 2308769245366350880
        mov     QWORD PTR [rbp-32], rax
        movabs rax, 7594769308319704608
        mov     QWORD PTR [rbp-24], rax
        mov     DWORD PTR [rbp-16], 538994038
        mov     BYTE PTR [rbp-12], 0
        lea     rax, [rbp-48]
        mov     rdi, rax
        call    countWords(char*)
        mov     esi, eax
        mov     edi, OFFSET FLAT:.LC0
        mov     eax, 0
        call    printf
        mov     eax, 0
        leave
        ret