The use of ASM in Visual C++

Write a course project. My task is to write a CLR library in which the function will be considered with assembleable insert. Wrote a function for a regular Windows Forms application, everything works fine. Put the function code in the library and throws an error. Tried to find on forums, write what you want to use ASMA in the settings of the build. Did so but the problem is not resolved. If you comment out the AFM — no errors Tell me how to get rid of this problem?

October 8th 19 at 02:56
1 answer
October 8th 19 at 02:58
Assembler blocks cannot be used in managed C++.
Try to make a function in
#pragma unmanaged
...
#pragma managed
here is the code of the library, tell me where to put please

#include "stdafx.h"
#include "kursa4_lib.h"
 
using namespace System;
 
namespace MathFuncs
{
 
float MyMathFuncs::Calc(float a, float b, float c, float d, float x, float mas[]){
float res,im;
if(x<10){
 
__asm{
fld [c]
fmul ST(0),ST(0)
fld [a]
fsub ST(0),ST(1)
fst [res]
}
 
} else if(x>10) {
__asm{
fld [a]
fmul ST(0),ST(0)
fld [b]
fadd ST(0),ST(1)
fstp [a]
fld [c]
fmul ST(0),ST(0)
fstp [b]
fld1
fld [b]
fsub ST(0),ST(1)
fstp [b]
fld1
fld [b]
fsub ST(0),ST(1)
fld [a]
fdiv ST(0),ST(1)
fst [res]
}
} else {
float m[5];
for(int i=0;i<5;i++){
m[i]=mas[i];
}
__asm{
fldz
fstp [c]
mov ecx, 5
start:
mov eax, 5
sub eax, ecx
mov ebx, 4
mul ebx
mov ebx, eax
lea eax, m
add eax, ebx
mov eax, [eax]
mov [im],eax
fld [im]
fmul ST(0),ST(0)
fld [c]
fadd ST(0),ST(1)
fstp [c]
loop start
fld [c]
mov [im], 3
fild [im]
fmul ST(0),ST(1)
fstp [c]
fld [b]
fld [a]
faddp ST(1),ST(0)
fstp [res]
mov [a], 3
fild [im]
fld [d]
faddp ST(1),ST(0)
fld [res]
fdiv ST(0),ST(1)
fstp [a]
fstp [b]
fstp [b]
fld [a]
fld [c]
fsub ST(0),ST(1)
fstp [res]
}
}
return res;
}
}
- princess_Bechtelar commented on October 8th 19 at 03:01

Find more questions by tags Visual StudioC++Assembler