I am getting a segmentation fault when my assembly program calls my C program bubblesort
in main i have:
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? ^^
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
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
Nobody has any ideas?
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
Later,
Frank
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
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
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.
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.
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.