[英]Run-Time Check Failure #2 - Stack around the variable 'IDNumber' was corrupted
[英]Run-Time Check Failure #2 - Stack around the variable 'result' was corrupted
我已经编译了这段代码,并获得运行时检查失败#2-变量'result'周围的堆栈损坏 。 但是,当我将结果数组大小从2更改为4时,异常消失了。 您能解释为什么会这样吗? 抱歉,如果您发现这个问题太基础了。
#include "stdafx.h"
string get_cpu_name()
{
uint32_t data[4] = { 0 };
_asm
{
cpuid;
mov data[0], ebx;
mov data[4], edx;
mov data[8], ecx;
}
return string((const char *)data);
}
void assembler()
{
cout << "CPU is " << get_cpu_name() << endl;
float f1[] = { 1.f , 22.f};
float f2[] = { 5.f , 3.f };
float result[2] = { 0.f };
/*float f1[] = { 1.f , 22.f , 1.f , 22.f };
float f2[] = { 5.f , 3.f , 1.f , 22.f };
float result[4] = { 0.f };*/
_asm
{
movups xmm1, f1;
movups xmm2, f2;
mulps xmm1, xmm2;
movups result, xmm1;
}
/*for (size_t i = 0; i < 4; i++)*/
for (size_t i = 0; i < 2; i++)
{
cout << result[i] << "\t";
}
cout << endl;
}
int main()
{
assembler();
getchar();
return 0;
}
movups
指令将128位(16字节)写入内存 。 您正在将此写入8字节数组的位置(2 * 4字节或64位)。 数组之后的8个字节也将被写入。
您应确保至少有16个字节的空间可写入结果,或者应确保在其中写入的空间少于16个字节。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.