Visual C 和内联装配代码在一个程序中具有相同的输出,但在另一个程序中具有不同的输出
visual C++ and inline assembly code have same output in one program, but different in another
我正在处理一个分配,在该分配中,我必须将C代码的摘要转换为内联汇编。该代码是渲染朱莉娅分形的程序的一部分。
我已经测试了两个代码片段的输出,并且它们完全匹配,但是我的程序仍然输出了不同的图像(适合C代码的朱莉娅fractal,一个用于内联装配代码的平面粉红色屏幕)。
这是功能的起始部分,也是返回
COLORREF render_point(const double &a,
const double &b, int N) {
double cRe = -0.5;
double cIm = -0.05;
double x(a), y(b);
double norm = x*x+y*y;
int n;
double three = 3.0;
(loop goes here)
return HSVtoRGB(n % 256, 255 , 255 *(n<N));
}
这是C代码
for (n = 0; norm < 4.0 && n < N; ++n)
{
double old_x = x;
double old_y = y;
x = (old_x * old_x * old_x) - (3 * old_y * old_y * old_x) + cRe;
y = (3 * old_y * old_x * old_x) - (old_y * old_y * old_y) + cIm;
norm = x*x+y*y;
}
和内联装配代码:
for (n = 0; norm < 4.0 && n < N; ++n)
{
__asm {
// Create (old_x * old_x * old_x)
fld x;
fmul x;
fmul x;
// Create (3 * old_y * old_y * old_x)
fld three;
fmul y;
fmul y;
fmul x;
// Create the full equation for x
fsubp st(1), st(0);
fadd cRe;
// Create (3 * old_y * old_x * old_x) + cIm
fld three;
fmul y;
fmul x;
fmul x;
fadd cIm;
// Create (old_y * old_y * old_y)
fld y;
fmul y;
fmul y;
fsubp st(1), st(0); // Create the full equation for y
fst y; // Store in y to use for next loop
fmul st(0), st(0); // Get y*y
fxch st(1); // Swap places of y*y with newly calculated x
fst x; // Store in x to use for next loop
fmul st(0), st(0); // Get x*x
faddp st(1), st(0); // Get x*x + y*y
fst norm; // Set loop variable
}
}
两个循环之间可能会导致程序中的输出不同?
as 1201 ProgramAlarm在评论中提到的,只需在每个环路迭代末尾弹出fPU的剩余值规范。
相关文章:
- 如何从Windows应用程序输出到标准?
- 在由Sublime文本3编译后在cmd上显示Java程序输出
- 如何从 Win32 C++ 应用程序输出到父控制台窗口?
- 而循环:简单的除法程序输出零,不明白为什么
- Qt creator 4.11,在应用程序输出面板中创建一个链接
- 使用复制构造函数的程序输出错误
- 为什么Qt Creator的应用程序输出不能从spdlog记录器打印
- 为什么在 Direct X 11 中没有我的程序输出?
- 我怎样才能阻止我的程序输出时间,它使我的程序难以阅读
- 程序输出奇怪的字符
- 程序输出"nan"
- 为什么我的C++程序输出不同的数字来将米转换为英尺?
- 3D 纹理大小会影响程序输出,而不会引发错误
- C++,程序输出无效输入,但继续通过循环
- 如何连接C++和Excel(从C++程序输出到Excel电子表格)
- 为什么我的C 程序输出乱码代码
- QT小部件应用程序输出到控制台
- 混淆了具有虚拟继承的程序输出
- 为什么我的C++程序输出这个
- 为什么我的程序输出不断变化?EAX寄存器不断更改值