at&asm inline c ++问题 [英] at&t asm inline c++ problem
问题描述
我的代码
const int howmany = 5046;
char buffer [howmany];
asm(lea buffer,%esi); //获取缓冲区的地址
asm(mov howmany,%ebx); //设置循环数
asm(buf_loop:); // Lable开始循环
asm(movb(%esi),%al); //将缓冲区[x]复制到al
asm(inc%esi); //递增缓冲区地址
asm(dec%ebx); //减少循环计数
asm(jnz buf_loop); //跳到buf_loop if(ebx> 0)
我的问题
我正在使用gcc编译器。出于某种原因,我的缓冲区/ howmany变量在我的asm眼中是未定义的。我不知道为什么。我只想将我的缓冲区数组的起始地址移动到esi寄存器中,并在将每个元素复制到al寄存器时循环多少次。
class =h2_lin>解决方案你在gcc中使用内联汇编器吗? (如果不是,在其他C ++编译器中,究竟是什么?)
如果是gcc,请参阅 here ,特别是这个例子:
asm(leal(%1,%1,4),%0
:= r(five_times_x)
:r(x)
);
%0
和%1
指的是C级变量,它们被具体列为第二个(用于输出)和第三个(用于输入)参数< / *没有输出寄存器* /
,以更明确地表示)。
My Code
const int howmany = 5046;
char buffer[howmany];
asm("lea buffer,%esi"); //Get the address of buffer
asm("mov howmany,%ebx"); //Set the loop number
asm("buf_loop:"); //Lable for beginning of loop
asm("movb (%esi),%al"); //Copy buffer[x] to al
asm("inc %esi"); //Increment buffer address
asm("dec %ebx"); //Decrement loop count
asm("jnz buf_loop"); //jump to buf_loop if(ebx>0)
My Problem
I am using the gcc compiler. For some reason my buffer/howmany variables are undefined in the eyes of my asm. I'm not sure why. I just want to move the beginning address of my buffer array into the esi register, loop it 'howmany' times while copying each element to the al register.
Are you using the inline assembler in gcc? (If not, in what other C++ compiler, exactly?)
If gcc, see the details here, and in particular this example:
asm ("leal (%1,%1,4), %0"
: "=r" (five_times_x)
: "r" (x)
);
%0
and %1
are referring to the C-level variables, and they're listed specifically as the second (for outputs) and third (for inputs) parameters to asm
. In your example you have only "inputs" so you'd have an empty second operand (traditionally one uses a comment after that colon, such as /* no output registers */
, to indicate that more explicitly).
这篇关于at&asm inline c ++问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!