从GCC内联汇编内的系统调用 [英] syscall from within GCC inline assembly
本文介绍了从GCC内联汇编内的系统调用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
是有可能写出使用系统调用从内联汇编块中的单个字符?如果是这样,怎么样?它应该看东西是这样的:
is it possible to write a single character using a syscall from within an inline assembly block? if so, how? it should look "something" like this:
__asm__ __volatile__
(
" movl $1, %%edx \n\t"
" movl $80, %%ecx \n\t"
" movl $0, %%ebx \n\t"
" movl $4, %%eax \n\t"
" int $0x80 \n\t"
::: "%eax", "%ebx", "%ecx", "%edx"
);
$ 80在ASCII'P',但不返回任何内容。
$80 is 'P' in ascii, but that returns nothing.
任何建议,多AP preciated!
any suggestions much appreciated!
推荐答案
类似
char p = 'P';
int main()
{
__asm__ __volatile__
(
" movl $1, %%edx \n\t"
" leal p , %%ecx \n\t"
" movl $0, %%ebx \n\t"
" movl $4, %%eax \n\t"
" int $0x80 \n\t"
::: "%eax", "%ebx", "%ecx", "%edx"
);
}
添加:请注意,我用 LEA
来加载炭的有效地址为 ECX
注册;为 EBX
的价值我想$ 0 $ 1和它似乎反正工作...
Add: note that I've used lea
to Load the Effective Address of the char into ecx
register; for the value of ebx
I tried $0 and $1 and it seems to work anyway ...
避免使用外部焦炭
int main()
{
__asm__ __volatile__
(
" movl $1, %%edx \n\t"
" subl $4, %%esp \n\t"
" movl $80, (%%esp)\n\t"
" movl %%esp, %%ecx \n\t"
" movl $1, %%ebx \n\t"
" movl $4, %%eax \n\t"
" int $0x80 \n\t"
" addl $4, %%esp\n\t"
::: "%eax", "%ebx", "%ecx", "%edx"
);
}
N.B:它的工作原理,因为英特尔处理器的字节序的! :D
N.B.: it works because of the endianness of intel processors! :D
这篇关于从GCC内联汇编内的系统调用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文