Thread: Segmantation fault in inline assembly! Any one please help....

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Registered User
    Join Date
    Feb 2012
    Posts
    3

    Post Segmantation fault in inline assembly! Any one please help....

    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
    Last edited by gn.times; 02-02-2012 at 12:52 AM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 7
    Last Post: 12-08-2010, 04:36 PM
  2. strcpy(), 2 strings, and segmantation fault
    By jigidyjensen in forum C Programming
    Replies: 4
    Last Post: 03-20-2009, 01:42 PM
  3. compare segmantation fault
    By realcr in forum C++ Programming
    Replies: 1
    Last Post: 07-28-2006, 05:56 PM
  4. Inline assembly
    By ^xor in forum C Programming
    Replies: 13
    Last Post: 07-05-2005, 06:32 AM
  5. Segmantation Fault (core dumped) error
    By Vinnie66 in forum C Programming
    Replies: 6
    Last Post: 03-25-2002, 01:34 PM

Tags for this Thread