Answered step by step
Verified Expert Solution
Link Copied!
Question
1 Approved Answer

This is the following code I have written in a file called Lab7.asm: .386 .model flat public _Square public _Multiply public _Divide .code _Square proc

This is the following code I have written in a file called Lab7.asm:

.386

.model flat

public _Square public _Multiply public _Divide

.code

_Square proc push ebp mov ebp, esp mov eax, [ebp + 8] imul eax pop ebp ret _Square endp

_Multiply proc push ebp mov ebp, esp mov eax, [ebp + 8] mov ebx, [ebp + 12] imul ebx pop ebp ret _Multiply endp

_Divide proc push ebp mov ebp, esp mov eax, [ebp + 8] mov ebx, [ebp + 12] mov ecx, [ebp + 16] mov edx, 0 idiv ebx mov ecx, eax mov ebx, [ebp + 20] mov ebx, edx pop ebp ret _Divide endp

end

And this is my C++ program:

#include using namespace std;

enum ResultCode {ShowSquare, ShowMultiply, ShowDivide, ShowRemainder, ShowDivideFailure}; enum SuccessCode {Failure, Success};

extern "C" SuccessCode Divide(long, long, long&, long&); extern "C" long Multiply(long, long); extern "C" void PrintResult(ResultCode, long); extern "C" long Square(long);

void main() { long Num1; long Num2; long Result; long Remainder; do { cout << "Enter Number to Square" << endl; cin >> Num1; Result = Square(Num1); cout << "Square is: " << Result << endl; cout << "Enter two numbers to multiply" << endl; cin >> Num1 >> Num2; Result = Multiply(Num1, Num2); cout << "Result of multiply is: " << Result << endl; cout << "Enter mumber to divide into then number to divide by" << endl; cin >> Num1 >> Num2; if (Divide(Num1, Num2, Result, Remainder) == Success) cout << "Result is " << Result << " and remainder is " << Remainder << endl; else cout << "Attempted division by zero"; } while (Result > 0); }

void PrintResult(ResultCode PrintCode, long Value) { switch (PrintCode) { case ShowSquare: cout << "Display of square is: " << Value << endl; break; case ShowMultiply: cout << "Display of multiply is: " << Value << endl; break; case ShowDivide: cout << "Display of divide is " << Value << endl; break; case ShowRemainder: cout << "Display of remainder is " << Value << endl; break; case ShowDivideFailure: cout << "Display of Division by zero" << endl; break; default: cout << "Error in assembly routines" << endl; } }

These are the instructions I was given:

Write the three functions (Square, Multiply, and Divide) required for the following C++ program. Square and Multiply will return the result to the calling program and will also call PrintResult to display the answer. If successful, Divide will return a 1, set the value of theresult and the remainder into the appropriate parameters, and call PrintResult twice (once for result and once for remainder). If Divide is not successful, it will return a 0 and call PrintResult to display the failure message. Link them to the above program to demonstrate their functionality.

I am a proficient C++ and Java programmer, but since this is my first semester working with Intel Assembly, things have been a bit weird. I've been fine on my own figuring things out up until this 7th homework lab. I've written the above assembly code by myself, but I'm stuck on what to do next. I tried calling PrintResult with the statement: call _PrintResult as the next step wants me to do, but this only results in the compiler telling me that the function is an undefined symbol. Also, how do I get my didvide function to return a 0 or 1 in the assembly code?

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image
Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Spatio Temporal Database Management International Workshop Stdbm 99 Edinburgh Scotland September 10 11 1999 Proceedings Lncs 1678

Authors: Michael H. Bohlen ,Christian S. Jensen ,Michel O. Scholl

1999th Edition

3540664017, 978-3540664017

More Books

Students explore these related Databases questions