I am getting a segmentation fault when my assembly program calls my C program bubblesort

in main i have:


push    dword Posted on 2010-04-19 13:43:03 by ZosoLzrd
Target OS, compiler, assembler, linker, and their build options, please? ^^
Posted on 2010-04-19 15:30:20 by ti_mo_n
I'm running Ubuntu KArmic, with NASM, and gcc for the .c.

i just run these commands:

gcc -c bubblesort.c

nasm -f elf -d ELF_TYPE -l cmpswap.lis cmpswap.asm

i also compile other assembly subprograms and main with:

nasm -f elf -l "programName".lis "programName".asm

Then:

gcc -o a.out driver.c main.o bubblesort.c cmpswap.o getarray.o showarray.o asm_io.o


I hope this is what you meant, i didn't really understand
Posted on 2010-04-19 15:57:29 by ZosoLzrd
Nobody has any ideas?
Posted on 2010-04-20 13:06:11 by ZosoLzrd
No answer yet, but a preliminary observation: printf doesn't print squat until the buffer is flushed. (one of C's dirty little secrets that only asmers know) Put a "\n" at the end of your strings, and at least you ought(?) to see the startup message...

Later,
Frank

Posted on 2010-04-20 16:47:47 by fbkotler
First thing you show (this is in "asm_main", not "main", right?) is "push dword " is correct, if it's "size equ ..." or so, you'd just want "push size". I suspect that's okay, so far. The other question is: size in bytes? or size in dwords (number of "items")? You're using it as number of items...

If you can't get this working, could you post your entire "asm_main" so we can build it without having to guess what you've done? I don't see anything "obvious" (obvious enough to penetrate the fog...).

Best,
Frank

Posted on 2010-04-20 17:24:18 by fbkotler
Ok, I placed "\n" in the string like you suggested, and it really helped defining the problem.
I didn't realize C passes the second parameter first on the stack.
So the segmentation fault occurred when i was treating the int as an array, and vice versa.

Its working correctly now, Thanks.
Posted on 2010-04-20 19:24:46 by ZosoLzrd

No answer yet, but a preliminary observation: printf doesn't print squat until the buffer is flushed. (one of C's dirty little secrets that only asmers know) Put a "\n" at the end of your strings, and at least you ought(?) to see the startup message...

Later,
Frank




And if the "\n" doesn't fix it (in the Netbeans IDE it doesn't, I found), you can force a flush with fflush(stdout);
That is the most reliable way.
Posted on 2010-04-21 02:27:11 by Scali