user1340099
user1340099

Reputation: 1

Unhandled exception at 0x93b3237d in project00.exe: 0xC0000005: Access violation

In my program when i exit the section of ASM code and returning to the C++ code i get the Unhandled exception at 0x93b3237d in project00.exe: 0xC0000005: Access violation. In Crtexe.c at line mainret = main(argc, argv, envp); and in the disassembly when the 0C is add to ESP. i think the problem might be the return address of the main function is get corrupted before returning and that causing it to fail. Program find the intersection and union of two sets. Using VS10 and am out of ideas.


    include "iostream.h"//modify line to show up in code block

    using namespace std;

    typedef int DWORD;      //4 btye double word
    typedef char BYTE;      //1 byte 
    typedef short WORD;     //2 byte double word

    int main(){ 

    int i =0;
    BYTE str0[50] = "1qaz2wsx3edc4rfv5tgb6yhn7ujm8ik,9ol.0p;/-[?]F!Q"; 
    BYTE str1[50] ="QAZ@WSX#EDC$RFV%TGB^YHN&UJM*IK)P:?_{?}|1`"; 
    DWORD length0 ; 
    DWORD length1 ;
    BYTE IntersectArray[50]; 
    BYTE result [100] ;

    __asm{
    p:
    pusha
    lea eax, str0
    call COUNT 
    mov length0,ecx
    lea eax, str1
    call COUNT 
    mov length1,ecx
    call INTERSECTION
    call JoinSet
    xor eax,eax
    popa
    ret




    COUNT: 
    mov ecx,0;
    Q: mov dl, [eax]
    cmp dl,0h
    JE cEND
    inc eax
    inc ecx
    jmp Q
    cEnd: ret


    INTERSECTION:
        lea edx, str0
        mov ebx, length0
        lea esi, IntersectArray
        first: mov al, [edx]
        mov ecx, length1
        lea edi, str1
        repne SCASB
        cmp ecx,0
        JNZ INTER
    Back:   inc edx
        cmp ebx,0
        JZ EXITSTUFF
        dec ebx
        jmp first

    INTER: mov [esi] , al
       inc esi
       jmp Back

    EXITSTUFF:
        mov [esi], 0
        ret

    JoinSet :
        lea edi, result
        lea esi, str0
        mov ecx, length0
        REP MOVSB   



            lea edx, str1
        mov ebx, length1
        lea esi, result + [ebx]
        f: mov al, [edx]
        mov ecx, length0
        lea edi, str0
        repne SCASB
        cmp ecx,0
        JNZ B
         mov [esi] , al
           inc esi
    B:      inc edx
        cmp ebx,0
        JZ EXITSTU
        dec ebx
        jmp f

    EXITSTU:
        mov [esi], 0
        ret
    }

rest

    for(int i =0;i < 50;i++){
cout <<IntersectArray[i];}
cout << endl;
for (int i =0; i<100;i++)
cout <<result[i];
cout << endl;
system("pause");
return 0;
}

Upvotes: 0

Views: 780

Answers (1)

Paul Mitchell
Paul Mitchell

Reputation: 3281

Probably a dumb comment since I've never done any x86 assembly. But I thought asm was inline? So what is your first 'ret' actually returning from?

Upvotes: 2

Related Questions