Hi
I'm new to linux programming. Please help me to solve this error
Linux version: Ubuntu
Compiler: GCC
Program: String concatenation using inline assembly.
Code:
- #include<stdio.h> #include<string.h> static inline char * asm_str_concat(char *d, char *s1, char *s2) { int rsrc1, rdest,rsrc2; __asm__ __volatile__( "1:lodsb\n\t;" "stosb\n\t;" "testb %%al,%%al\n\t;" "jne 1b;" "dec %%di;" "movl %%ecx,%0;" "2:lodsb\n\t;" "stosb\n\t;" "testb %%al,%%al\n\t;" "jne 2b;" : "=&S" (rsrc2), "=&D" (rdest),"=a"(s2) : "0" (s2),"1" (d),"c" (s1) ); return d; } int main(int argc,char *argv[]) { char dest2[512]; char *src1; char *src2; char *d2; src1=argv[1]; src2=argv[2]; printf("%d",*argv[1]); printf("%s",src1); printf("%s\n",src2); d2 = asm_str_concat(dest2, src2,src1 ); printf("%s\n",dest2); return 0; }
Error: Segmentation fault (core dumped) after giving 2nd string.
The program works fine if I give the input strings in main program directly.
But if I try to get the inputs from command line its getting 1st input and 2nd input strings then showing segmentation fault. So there shud be a problem in passing the strings to inline program. i'm not able to figure it out.
Please help me....
Thanks in advance