Author Topic: Segmentation fault in a snippet for C++  (Read 8 times)

Offline Xotes

  • New Member
  • Posts: 1
Segmentation fault in a snippet for C++
« on: Today at 01:33:41 PM »

I'm a student in computer science and I have to create a small program in assembly. This program must then be used in a C++ program.
Now onto the purpose : it must take a destination vector, a source vector and the length of thoses vectors (which is the same), take every number in the first vector, multiply it by two and then put it in the second vector.

My problem is this, for the core of the program, it looks like this :
    xor edi, edi ; initialising edi at 0 for the offset
    mov esi, [edx + edi*4] ; getting the value from the source table
    shl esi, 1 ; multiplying the taken value by 2
    mov [eax + edi*4], esi ; putting the value in the destination table
    inc edi
    loopnz table_multiplier

ecx contains the length of the vector. When I run it in sasm, I don't have any problem. But when I try using it in my C++ code, I get a segmentation fault. I've been trying to wrap my head around this for a day now and I can't seem to find the problem.

Thanks in advance if anyone can help :)

Offline fredericopissarra

  • Jr. Member
  • *
  • Posts: 25
Re: Segmentation fault in a snippet for C++
« Reply #1 on: Today at 02:16:28 PM »
How you are implementing this routine for use of your C/C++ code? For what OS? What C/C++ compiler? 32 or 64 bits?

MS ABI and SysV ABI calling conventions are very different, in both cases (i386 and amd64), and non-static member functions have a hidden argument ("this" pointer)...
« Last Edit: Today at 02:21:55 PM by fredericopissarra »