View previous topic :: View next topic |
Author |
Message |
slack_eater n00b
Joined: 20 Oct 2010 Posts: 5
|
Posted: Wed Oct 20, 2010 11:44 am Post subject: [Solved] Convert assembly to AT&T syntax |
|
|
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 |
|
|
avendesora Veteran
Joined: 16 Aug 2002 Posts: 1739 Location: Betelgeuse vicinity
|
Posted: Wed Oct 20, 2010 4:54 pm Post subject: |
|
|
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 |
|
|
slack_eater n00b
Joined: 20 Oct 2010 Posts: 5
|
Posted: Wed Oct 20, 2010 6:25 pm Post subject: |
|
|
Thanks!
It works great! |
|
Back to top |
|
|
|
|
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
|
|