Gentoo Forums
Gentoo Forums
Gentoo Forums
Quick Search: in
[Solved] Convert assembly to AT&T syntax
View unanswered posts
View posts from last 24 hours

 
Reply to topic    Gentoo Forums Forum Index Portage & Programming
View previous topic :: View next topic  
Author Message
slack_eater
n00b
n00b


Joined: 20 Oct 2010
Posts: 5

PostPosted: Wed Oct 20, 2010 11:44 am    Post subject: [Solved] Convert assembly to AT&T syntax Reply with quote

Hello to everyone,

does anyone know how to convert the following C-assembly inline code from the Intel syntax to the AT&T syntax?
Is there a way to use the intel syntax with gcc?

Code:
#include <stdio.h>

#define MAXLEN 80

main(void)
{
   unsigned char text[MAXLEN + 1];
   unsigned long len;

   scanf("%s", &text);

   __asm
   {
     mov -1, ecx
          start_loop:
          inc ecx
          cmp text[ecx], 0
          jne start_loop
          mov len, ecx
   }

   printf("%d", len);
}


Thanks in advance :)


Last edited by slack_eater on Wed Oct 20, 2010 9:03 pm; edited 1 time in total
Back to top
View user's profile Send private message
avendesora
Veteran
Veteran


Joined: 16 Aug 2002
Posts: 1739
Location: Betelgeuse vicinity

PostPosted: Wed Oct 20, 2010 4:54 pm    Post subject: Reply with quote

Check out this reference.

The following appears to work (32bit mode).

Code:
#include <stdio.h>

#define MAXLEN 80

int main(void)
{
    char text[MAXLEN+1];
    unsigned long len;

    scanf("%s", text);
    __asm__(
            "   mov  $-1, %%ecx\n\t"
            "start_loop:\n\t"
            "   inc  %%ecx\n\t"
            "   cmpb $0, (%1,%%ecx)\n\t"
            "   jne  start_loop\n\t"
            "   mov  %%ecx, %0\n\t"
            : "=r"(len)
            : "r"(text)
            : "%ecx"
           );

    printf("%lu", len);
    return 0;
}
Back to top
View user's profile Send private message
slack_eater
n00b
n00b


Joined: 20 Oct 2010
Posts: 5

PostPosted: Wed Oct 20, 2010 6:25 pm    Post subject: Reply with quote

Thanks!

It works great! :D
Back to top
View user's profile Send private message
Display posts from previous:   
Reply to topic    Gentoo Forums Forum Index Portage & Programming All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum