我已經寫了下面的彙編代碼來將字符串從小寫字母轉換爲大寫字母,它並不完全工作,因爲我無法訪問字符串的地址, m轉換。這段代碼不工作爲什麼?在gcc中的內聯彙編中訪問字符串的地址
#include<stdio.h>
int convert(char *str)
{
char *ptr;
__asm__ __volatile__ ("movl (%1),%%ebx;"
"subl $1,%%ebx;"
"movl %%ebx,%0;"
"REPEAT: addl $1,%%ebx;"
"testl %%ebx,%%ebx;"
"je END;"
"movzbl 0(%%ebx),%%ecx;"
"cmpl $97, %%ecx;"
"jb END;"
"cmpl $122,%%ecx;"
"ja END;"
"subb $32,0(%%ebx);"
"jmp REPEAT;"
"END: movl %%ebx,(%0);"
:"=r" (ptr)
:"r" (str)
);
printf("converted string =%s\n", str);
}
int main()
{
int i;
char str[] = "convert";
i = convert(str);
return 0;
}
你的問題是什麼?請問一個問題。 – fuz 2014-11-05 16:47:07
@FUZxxi:我無法訪問字符串的地址,並且上面的代碼不起作用! – goal4321 2014-11-05 16:55:40
你在哪一點指定'ptr'或'str'? – fuz 2014-11-05 16:56:50