Ошибка в сборке x86 с использованием Visual Studio - PullRequest
1 голос
/ 06 апреля 2020

Я получаю исключение переполнения стека при запуске этого фрагмента кода. Это краткий пример реальной программы, в которой я использую локальные переменные. Проблема возникает при выполнении этой инструкции: mov ebx, [edi + 4 * ebx]. Может кто-нибудь мне помочь?

#include <iostream>

using namespace std;
const int n = 9;


int main()
{
    unsigned int* v = new unsigned int[n];

    for (unsigned int i = 0; i < n; i++)
    {
        v[i] = i;
    }

    __asm
    {
        push ebp
        mov ebp, esp
        sub esp, 8                  // We reserve the corresponding space for 6 local variables

        mov edi, v                  // We move the vector v into edi

        mov eax, 0                  // We store into eax the position 0
        mov ebx, 0                  // We store into ebx the position 1
        mov eax, [ebp - 4]          // We move into eax the current position of the vector
        mov ebx, [ebp - 8]          // We move into ebx the proper jump in order to compare both positions
        add ebx, eax                // We add to eax the required jump
        mov ebx, [edi + 4 * ebx]    // We move into ebx the value of the position in ebx
        mov eax, [edi + 4 * eax]    // We move into eax the value of the position in eax
        cmp eax, ebx                // We compare both values and...

        mov esp, ebp                // We restore the base pointer
        pop ebp
    }
}
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...