Question
You will write an assembly program to act as a limited interactive scientific calculator that operates on floating point values. No C++ libraries other than iostream should be used. Using whichever IDE you like and whichever assembly syntax you prefer, write some inline assembly to complete the following C++ program:
int main () {
char operation;
float param, result;
std: : cout << "Which operation would you like to perform?\n";
std: : cout << " (s) sine, (c) cosine, (t) tangent\n";
std: : cout << " (a) area of a circle, (v) volume of a sphere\n";
std: : cout << " (g) log_2, (n) 1n, (1) log_10\nn;
std: : cin >> operation;
// Still in C++: Prompt for one operand
// The area & volume computations should prompt for the radius
11 Your C++ code should only be doing input & output--the --
// assembly should be doing the actual calculations
asm
(
Your assembly code goes here
Set up registers to pass in variable values
};
// Print out the results in C++ here
return 0
}
Solution Preview
This material may consist of step-by-step explanations on how to solve a problem or examples of proper writing, including the use of citations, references, bibliographies, and formatting. This material is made available for the sole purpose of studying and learning - misuse is strictly forbidden.
#include <iostream>int main()
{
char operation;
float param, result;
std::cout << "Which operation would you like to perform?\n";
std::cout << "(s) sine, (c) cosine, (t) tangent\n";
std::cout << "(a) area of a circle, (v) volume of a sphere\n";
std::cout << "(g) log_2, (n) ln, (l) log_10\n";
std::cin >> operation;
// Still in C++: Prompt for one operand
// The area & volume computations should prompt for the radius
// Your C++ code should only be doing input & output--the
// assembly should be doing the actual calculations
if ((operation == 'a') || (operation == 'v'))
{
std::cout << "Enter the radius:\n";
}
else
{
std::cout << "Enter the operand:\n";
}
std::cin >> param;
__asm
{
fld param // load param into FPU stack
mov eax, 1 // load 1 into eax register
mul operation // multiply it with operation to get operation in eax
// Calculate sine
cmp eax, 0x73 // check if operation is 's'
jne checkCosine // if not continue checking
fsin...