Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "pch.h"
- #include <iostream>
- using namespace std;
- //вариант 20: (b/2 - 53/c)/(b - a*c + 1)
- void cppcalc(double a, double b, double c) {
- cout << endl << "System computing: ";
- int zero_flag = 0;
- int of_flag = 0;
- if (c == 0 || (b - a * c + 1) == 0) {
- cout << "Division by zero" << endl;
- return;
- }
- cout << (b / 2 - 53 / c) / (b - a * c + 1) << endl;
- return;
- }
- void calc(double a, double b, double c) {
- cout << "Asm computing: ";
- int zero_flag = 0;
- int of_flag = 0;
- double result = 0.0;
- double t2 = 2;
- double t1 = 1;
- double t53 = 53;
- _asm {
- finit
- fld b // b (0)
- fld t2 // t2(0), b(1)
- fdiv // b/2 (0)
- fld t53 // t53 (0), b/2 (1)
- fld c // c (0), t53 (1), b/2 (2)
- ftst
- fstsw ax
- sahf
- je zero_f
- fdiv // 53/c(0), b/2 (1)
- fsub // b/2 - 53/c (0)
- fld b // b (0), b/2 - 53/c (1)
- fld a
- fmul c // a*c (0), b (1), b/2 - 53/c (2)
- fsub // b - a*c (0), b/2 - 53/c (1)
- fadd t1 // b - a*c + 1 (0), b/2 - 53/c (1)
- ftst
- fstsw ax
- sahf
- je zero_f
- fdiv // (b/2 - 53/c)/(b - a*c + 1) (0)
- fstp result // result = (b/2 - 53/c)/(b - a*c + 1)
- fxam //&&&
- jmp end_of_code
- zero_f : ; флаг ошибки деления на ноль
- mov eax, zero_flag
- inc eax
- mov zero_flag, eax
- jmp end_of_code
- end_of_code : ;
- }
- if (zero_flag == 1) {
- cout << "Division by zero" << endl;
- return;
- }
- if (zero_flag == 0)
- cout << "(b/2 - 53/c)/(b - a*c + 1) = " << result << endl;
- }
- int main() {
- cout << "a:";
- double a;
- cin >> a;
- cout << endl << "b:";
- double b;
- cin >> b;
- cout << endl << "c:";
- double c;
- cin >> c;
- cout << endl;
- calc(a, b, c);
- cppcalc(a, b, c);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement