in the name of zero

December 30, 2005

gcc inline

Filed under: hermetic studies

ok. so i know a little c. and i know a little asm. where do i go from here? basic gcc inline assembly.

int main(int argc, char **argv)
{
        int ctr;
        ctr = 1;
        do {
                printf("%d\n", ctr);    
	
                /*
                 * try changing ctr++ to inline asm
                 * something like an incrementor
                 */
                __asm__("inc %%ecx"             /* ctr ++ */
                                :"=c" (ctr)     /* ctr => ecx */
                                :"c" (ctr)      /* ecx <= ctr */
                        );
	
        } while (ctr < 11);
	
        /* this time, i'll try exchanging values */
	
        int first = 1;
        int second = 2;
	
        __asm__(""
                : "=b" (first), "=a" (second)
                : "a" (first), "b" (second)
               );
	
        printf("inverted : %d  %d\n", first, second);
        return 0;
}

fantastic. learning c and assembly is fun. i promise to experiment with _real life_ activities next time. you know, like dating and flirting. stuff like that.

1 Comment »

The URI to TrackBack this entry is: http://gnurbs.blogsome.com/2005/12/30/gcc-inline/trackback/

  1. Hey Belated Merry Christmas to you and your Family… and Happy new year.. =)take care and Godspeed

    Comment by Angel — December 31, 2005 @ 1:23 pm

RSS feed for comments on this post.

Leave a comment

Line and paragraph breaks automatic, e-mail address never displayed, HTML allowed: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <code> <em> <i> <strike> <strong>


Get free blog up and running in minutes with Blogsome | Theme designs available here