V
V
Vadim2018-12-15 16:59:24
assembler
Vadim, 2018-12-15 16:59:24

Where is the error in the code, coprocessor?

5c1508797b1d7971066149.pngChecked step by step, the error is at the end.
It counts separately correctly, when I start adding the expression (to divide the first part into the second), the result does not converge with SI.

#include <windows.h>
#include <stdio.h>
#include <math.h>

int main() {
  SetConsoleCP(1251);
  SetConsoleOutputCP(1251);
  double c, d, a, b = 23, k = 2, result_C = 0, result_ASM = 0, x = 1, y = 4;
  printf("Введите c: "); scanf_s("%lf", &c);
  printf("Введите d: "); scanf_s("%lf", &d);
  printf("Введите a: "); scanf_s("%lf", &a);
  result_C = (2 * c) - (d/23) / log(1 - a / 4);
  __asm {
    finit; // инициализация сопроцессора
    fld d; // st = d;
    fdiv b; // st = d/b;
    fld k; // st = k, st(1) = d/b
    fmul c; // st=k*c, st(1) = d/b
    fsub; // st= k*c-d/b
    FCHS;
    //
    fld1; // st = 1; st(1)=k*c-d/b
    fld a;  // st = a, st(1) = x, st(2)=k*c-d/b 
    fdiv y; // st = a/y, st(1) = 1, st(2)=k*c-d/b 
    fsub;  // st = 1 - a/y;  st(1)=k*c-d/b
    fldln2; // st = ln(2), st(1) = a/y - x; st(2)=k*c-d/b
    fld st(1); // st(0) = a/y - x, st(1) = ln(2),st(2)= a/y - x, st(3) = k*c-d/b
    fyl2x;  // st(0) = ln(1 - a / y), st(2) = k*c-d/b
    fxch st(2); // st = k*c-d/b , st(2)= ln(1 - a / y);
    fdiv st,st(2);
    fstp result_ASM; // result;
  }
  printf("RESULT C: %f\n", result_C);
  printf("RESULT ASM: %f\n", result_ASM);
  system("pause");
  return 0;
}

Answer the question

In order to leave comments, you need to log in

2 answer(s)
V
Vadim, 2018-12-15
@POBOGO

The question is closed. Found an error.

#include <windows.h>
#include <stdio.h>
#include <math.h>

int main() {
  SetConsoleCP(1251);
  SetConsoleOutputCP(1251);
  double c, d, a, b = 23, k = 2, result_C = 0, result_ASM = 0, x = 1, y = 4;
  printf("Введите c: "); scanf_s("%lf", &c);
  printf("Введите d: "); scanf_s("%lf", &d);
  printf("Введите a: "); scanf_s("%lf", &a);
  result_C = ((2 * c) - (d/23)) / (log(1-a/y));
  __asm {
    finit; // инициализация сопроцессора
    fld d; // st = d;
    fdiv b; // st = d/b;
    fld k; // st = k, st(1) = d/b
    fmul c; // st=k*c, st(1) = d/b
    fsub; // st= k*c-d/b
    FCHS;
    //
    fld1; // st = 1; st(1)=k*c-d/b
    fld a;  // st = a, st(1) = x, st(2)=k*c-d/b 
    fdiv y; // st = a/y, st(1) = 1, st(2)=k*c-d/b 
    fsub;  // st = 1 - a/y;  st(1)=k*c-d/b
    fldln2; // st = ln(2), st(1) = a/y - x; st(2)=k*c-d/b
    fld st(1); // st(0) = a/y - x, st(1) = ln(2),st(2)= a/y - x, st(3) = k*c-d/b
    fyl2x;  // st(0) = ln(1 - a / y), st(2) = k*c-d/b
    fxch st(2); // st = k*c-d/b , st(2)= ln(1 - a / y);
    fdiv st, st(2);
    fstp result_ASM; // result;
  }
  printf("RESULT C: %f\n", result_C);
  printf("RESULT ASM: %f\n", result_ASM);
  system("pause");
  return 0;
}

result_C = (2 * c) - (d/23) / log(1 - a / 4); --> result_C = ((2 * c) - (d/23)) / (log(1-a/y));

S
Saboteur, 2018-12-15
@saboteur_kiev

result_C = (2 * c) - (d/23) / log(1 - a / 4);
You have division first and then subtraction. Put 2(*c) - d(/23) in extra brackets.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question