Ruslan Vaitukevich
Ruslan Vaitukevich

Reputation: 11

Difference of sets and read access violation

I'm trying to find a difference of sets (I use vectors but idea is the same: arr1 \ arr2) using inline assembly in VS. But I can't get rid of the following error: "An exception was thrown: read access violation. ptr1 was 0xFFFFFFD7". And for some reason it is always 0xFFFFFFD7. It's worth noting that the error appears after I perform deleting. I'd be extremely grateful if you could help me figure this out.

std::vector<int> arr1 = {8, 3};
std::vector<int> arr2 = {7, 8};
int* ptr1 = arr1.data() - 1;
int size1 = arr1.size();
int* ptr2 = arr2.data() - 1;
int size2 = arr2.size();
int numberOfDeletes = 0;
__asm {
    mov ebx, ptr2
    mov edx, 0
    _array2:
        mov eax, ptr1
        mov ecx, size1
        cmp edx, size2
        je _out
        add ebx, 4
        mov esi, dword ptr[ebx]
    _comparing:
        add eax, 4
        cmp dword ptr [eax], esi
        je _delete
        loop _comparing
        inc edx
        jmp _array2
    _delete:
        mov edi, eax
        add edi, 4
        mov ebp, dword ptr [edi]
        mov dword ptr [eax], ebp
        add eax, 4
        loop _array2
    _out:
        add eax, 4
        mov ptr1, eax
        mov eax, numberOfDeletes
        sub size1, eax
}

I tried using the lea commmand like this: lea eax, arr1[0], but it doesn't work as I expect it to because the pointer from arr1.data() and the adress I get using lea are different.

Upvotes: 1

Views: 55

Answers (0)

Related Questions