- c - 在位数组中找到第一个零
- linux - Unix 显示有关匹配两种模式之一的文件的信息
- 正则表达式替换多个文件
- linux - 隐藏来自 xtrace 的命令
错误:
Run-Time Check Failure #2 - Stack around the variable 'arr' was corrupted.
这似乎是这个论坛上的一个常见错误;但是,我找不到其中混入了汇编代码的程序。基本上,我的程序是将十进制转换为二进制(16 位表示)。完成编码后,一切似乎都可以正确计算,并且可以毫无问题地将十进制转换为二进制;但是,在 “按任意键继续......” 之后,会弹出上述错误。
我不认为是 C++ 代码导致了这个问题,因为它非常基础,而且只用于调用汇编函数。
同样,计算是正确的,因为程序将产生正确的转换(即:十进制 = 10,二进制转换:0000000000001010),但只是在程序结束时给我错误。
C++代码:
#include <iostream>
using namespace std;
extern"C" void decToBin(char[], int, int);
int main()
{
//Initialize array and variables
const int SIZE = 16;
char arr[SIZE] = { NULL };
int dec = 0;
//Ask user for integer that they want to convert
cout << "Please enter integer you want to convert to binary: ";
cin >> dec;
//Assembly function to convert integer
decToBin(arr, dec, SIZE);
cout << "The 16-bit binary representation of " << dec << " is: ";
//Display the 16-bit binary conversion
for (int i = 0; i < SIZE; i++)
cout << arr[i];
cout << endl;
system("PAUSE");
return 0;
}
汇编代码:
.686
.model flat
.code
_decToBin PROC ;Start of project
start:
push ebp
mov ebp,esp ;Stack pointer to ebp
mov eax,[ebp+8] ;Address of first array element
mov cx,[ebp+12] ;Integer number being passed - Copying onto 16 bit register
mov edx,[ebp+16] ;Size of array
loopme: ;Loop to fill in array
mov ebx,0 ;Initializes ebx to store carry flag after shift
cmp edx,0 ;Compare edx with 0 to see if we should continue
je alldone
shl cx,1 ;Shift the value to the left
adc ebx,0 ;Check carry flag and add 1 if CF(CY) is set to 1 and stay at 0 if CF(CY) is 0
add ebx,48 ;Since array is CHAR, adding 48 will give correct 0 or 1 instead of null
mov [eax],ebx ;Copy the 0's or 1's into the array location
dec edx ;Decrement the counter
inc eax ;Move the array up an index
jmp loopme
alldone:
pop ebp
ret
_decToBin ENDP
END
最佳答案
我没有汇编程序来编译你的代码,但你在这一行将 32 位值写入 char[]
:
mov [eax],ebx ;Copy the 0's or 1's into the array location
因此,最后一次写入会将内存位置 arr[SIZE-1]
更新为 arr[SIZE+2]
。
关于c++ - x86 Intel Assembly 和 C++ - 数组周围的堆栈已损坏,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33790106/
循环不起作用,我想就是这样,也许 list[i].removeChild(list[i]);我想删除 lt 列表类。 function removeDone () { var lista = do
我正在制作一个java程序,它能够使用他们的api将(主要是mp4)文件上传到主机openload.co,你可以找到here . 我的程序可以上传 mp4 视频,但无法播放。当我下载以前上传的视频并通
我在服务器端使用 jquery-file-upload 和 Python-Flask。每当我上传 100mb 以上的大文件时,上传的版本比原始版本稍大并且无法打开(已损坏)。我对 10mb block
已关闭。这个问题是 off-topic 。目前不接受答案。 想要改进这个问题吗? Update the question所以它是on-topic用于堆栈溢出。 已关闭10 年前。 Improve th
我有一个按钮,它是我的 Magento 主题中提供的代码的一部分,根据日期/时间戳,我没有无意中编辑它。我确信它在某些时候是有效的,但回顾一下上周我的源代码控制,我似乎无法找出哪里出了问题。 这是按钮
我有一个将一些数据写入新文件的简单函数。它可以工作,并且文件已写入,但在 MSVS Express 2013 中调试时出现上述错误。 void writeSpecToFile(const char *
我试图包含我的应用程序的国际化,并且仅出于测试目的,我在文件 Localized.string 中添加了一行简单的代码。 这是我的整个文件: "Test locale" = "Test locale"
这是代码: console.log(234, document.links); console.log(235, document.links.length); 输出显示数组中有值,但返回 0。 这是
我在尝试使用 ASP.NET MVC3 的 Ajax.BeginForm 方法时遇到了一个奇怪的问题。表单通过正确的操作属性在页面上正确呈现。但是,当提交表单时,“OnFailure”事件返回“Not
我是 10 年级的学生,我在 APCS 的最终项目是制作一个游戏/应用程序并提交代码、运行视频和书面回复。我的问题是整个类(class)都是使用 Code.org 的 AppLab 进行教学的,并且
我正在使用带有 Microsoft auth 的 azure webapp。几个月来一直工作良好。 然而今天它坏了。login.microsoftonline.com 页面因 css 和 js 加载错
我遇到了一个奇怪的问题。直到几分钟前才出现问题。在不对 less/css 文件进行任何更改的情况下(从不),引导按钮和导航栏标题的外观突然发生了变化。在第一张图片上,您可以看到按钮应该是什么样子,在第
我正在开发一个用于核心转储处理的工具。使用 sysctl 我将其设置为获取工具输入的核心转储。一切都运转良好。但今天我面临着(我不知道为什么)coredump 损坏的情况。当我将常规文件设置为核心转储
我对一个我继承但并非最初创建的网站感到非常头疼。几乎所有的样式都是通过一个样式表完成的。问题是自动调整大小不再有效,所有页面现在都以指定的最小宽度显示。随着时间的推移,各种不同的人添加了它,CSS 变
我正在尝试使用 AngularJS 甚至纯 JavaScript 将 HTML 表格转换为 XLSX。 当我使用下面的方法转换为 XLS 时,它的下载正常并且 XLS 文件正在打开。 var blob
需要根帮助导致 vtable 损坏问题(不确定这是否正在发生)。这是代码的非常简化的版本。 class CBase { public: CBase() virtual ~CBase()
一段时间未在 Play 商店中更新我的应用程序后,我尝试使用我的 keystore 对我的一个 APK 进行签名,结果发现 keystore 和别名密码不再起作用。我可以使用此要点重置的 keysto
已安装 XCode 6在 Mavericks .它不运行。将操作系统更新为 Yosemite 10.10 :现在 Xcode.app(通过 *.dmg 安装)启动失败并显示错误消息 “Xcode” i
我有一个在我的应用程序中使用的 plist 文件,我可以对其进行本地化,因此我在我的项目中得到两个条目,一个用于英语,一个用于西类牙语,当我编译运行该应用程序时,它可以工作,但当然在这个阶段内容是相同
我相信这是来自 androidsnippets.org 的 fragment - 为什么它在 Android 2.3 上不起作用?如何解决? 错误 03-05 23:19:17.479: WARN/S
我是一名优秀的程序员,十分优秀!