Answer the question
In order to leave comments, you need to log in
How to solve this with assembler?
I have an expression, I need to solve it using assembler insert in c ++
#include "iostream"
using namespace std;
int main()
{
short x, y, z, f1, f2;
cout << "x = ";
cin >> x;
cout << "y = ";
cin >> y;
cout << "z = ";
cin >> z;
/*
Formula:
(4*x*x - 3)/5*y, (x > 5 || y == 5) && y != 0;
(y - 3)/z + 2, z != 0 && x <= 5;
y*y - 3, otherwise;
(1)
x = 10
y = 5
z = 5
f = 15 / result
(2)
x = 3
y = 21
z = 7
f = 4 / result
(3)
x = 6
y = 0
z = 3
f = -3 / result
*/
/* Check on C++ the right result */
if ((x > 5 || y == 5) && y != 0)
{
f1 = (4 * x * x - 3) / (5 * y);
cout << "f1 = (4 * x * x - 3) / (5 * y) = " << f1 << endl;
}
else if (z != 0 && x <= 5)
{
f1 = (y - 3) / z + 2;
cout << "f1 = (y - 3) / z + 2 = " << f1 << endl;
}
else
{
f1 = y * y - 3;
cout << "f1 = y * y - 3 = " << f1 << endl;
}
_asm {
//(x > 5 || y == 5)
cmp y, 5
je m1
cmp x, 5
jg m1
//z!=0;
cmp z, 0
jne m2
m1 :
//&& y != 0
cmp y, 0
je m3
//(4*x*x - 3)/5*y
mov ax, 4
imul x
imul x
sub ax, 3
mov bx, 5
xchg ax, bx
imul y
xchg ax, bx
CWD
idiv bx
//jump to result
jmp stop
m2 :
//&& x <= 5 - не обязательно
cmp x, 5
jg m3
// (y - 3)/z + 2
mov ax, y
sub ax, 3
CWD
idiv z
add ax, 2
//jump to result
jmp stop
m3 :
// y*y - 3
mov ax, y
imul y
sub ax, 3
//jump to result
jmp stop
stop :
mov f2, ax
}
cout << "F (C++) = " << f1 << endl;
cout << "F (ASM) = " << f2 << endl;
system("PAUSE");
return 0;
}
_asm {
//(y > 0 || z == 5)
cmp z, 0
je m1
cmp y, 0
jg m1
//x == 0;
cmp x, 0
je m2
}
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question