小编And*_*yen的帖子

x86英特尔汇编和C++ - 堆栈数据损坏

错误:

Run-Time Check Failure #2 - Stack around the variable 'arr' was corrupted.
Run Code Online (Sandbox Code Playgroud)

这似乎是这个论坛上的一个常见错误; 但是,我无法找到一个混合了汇编代码的程序.基本上,我的程序是将十进制转换为二进制(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; …
Run Code Online (Sandbox Code Playgroud)

c c++ assembly

3
推荐指数
1
解决办法
286
查看次数

时间复杂度 - While 循环除以 2 并嵌套 for 循环

我陷入了即将到来的期中考试的复习问题,非常感谢任何帮助。

请看下面的函数:

void george(int n) {                
    int m = n;                              //c1 - 1 step
    while (m > 1)                           //c2 - log(n) steps
    {                       
        for (int i = 1; i < m; i++)         //c3 - log(n)*<Stuck here>
          int S = 1;                        //c4 - log(n)*<Stuck here>
        m = m / 2;                          //c5 - (1)log(n) steps
    }
}
Run Code Online (Sandbox Code Playgroud)

我陷入了内部 for 循环,因为每次迭代后 i 都在递增,并且 m 被除以 2。

如果 m = 100:第一次迭代 m = 100:循环将运行 100 次,i 迭代 100 次 + 1 用于最后一次检查 第二次迭代 m …

algorithm time complexity-theory big-o

0
推荐指数
1
解决办法
3273
查看次数

标签 统计

algorithm ×1

assembly ×1

big-o ×1

c ×1

c++ ×1

complexity-theory ×1

time ×1