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

ASSEMBLY LANGUAGE HW Programming Floating-Point Arithmetic Implement functions t

ID: 3576358 • Letter: A

Question

ASSEMBLY LANGUAGE HW

Programming Floating-Point Arithmetic

Implement functions that perform calculation according to the tasks given below. All input and output variables must be of floating-point type (C/C++ float or double). Find correct formulas by yourself and define the required parameters and types in order to compute the result.

Note: Calculations, conditions and jumps may be implemented with Inline Assembler! Keep in mind that if you are using assembler module, then to return the floating-point result from the function by convention it must be placed in the FPU data register ST(0).

Apply The x87 FPU instructions for the solutions. Use the template below please and the app should be run without error.

Task for grade level 6: Calculate the area of parallelogram then the length of sides and angle between them is given.

Task for grade level 8: Calculate the surface area of cone when base radius and height is given.

Please use template below for the solutions;

#include "stdafx.h"

#include

#include

// For each grade level variant implement own function, e.g.:

double solution_for_grade_X(double a, double b, double c)

{

    double r;

    __asm

    {

        // Your Inline Assembler instructions for grade level X go here

        // :::

       fst QWORD PTR [r]    ; r = st(0)

    }

    return r; // Please note that in assembler module the result must be placed in st(0)!

}

int main()

{

    // Change the parameters according to your grade level function, e.g.:

    double r = solution_for_grade_X(1.5, 2.3, 5.6);

    // Print the result vector to the console:

    _tprintf(_T("%d "), r);

    // :::

    return 0;

}

Explanation / Answer

Answer:

.LC1:
        .string "Enter Base "
.LC2:
        .string "Enter Height   "
.LC3:
        .string "Area of Parallelogram "
main:
        push    rbp
        mov     rbp, rsp
        sub     rsp, 48
        movsd   xmm0, QWORD PTR .LC0[rip]
        movsd   QWORD PTR [rbp-8], xmm0
        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-24]
        mov     rsi, rax
        mov     edi, OFFSET FLAT:std::cin
        call    std::basic_istream<char, std::char_traits<char> >::operator>>(double&)
        mov     esi, OFFSET FLAT:.LC2
        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-32]
        mov     rsi, rax
        mov     edi, OFFSET FLAT:std::cin
        call    std::basic_istream<char, std::char_traits<char> >::operator>>(double&)
        movsd   xmm1, QWORD PTR [rbp-24]
        movsd   xmm0, QWORD PTR [rbp-32]
        mulsd   xmm0, xmm1
        movsd   QWORD PTR [rbp-16], xmm0
        mov     esi, OFFSET FLAT:.LC3
        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     rax, QWORD PTR [rbp-16]
        mov     QWORD PTR [rbp-40], rax
        movsd   xmm0, QWORD PTR [rbp-40]
        mov     rdi, rdx
        call    std::basic_ostream<char, std::char_traits<char> >::operator<<(double)
        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     .L5
        cmp     DWORD PTR [rbp-8], 65535
        jne     .L5
        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
.L5:
        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
.LC0:
        .long   1413551940
        .long   1074340347

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