Linux上的C内联汇编,将字符串从堆栈写入到stdout
我如何将字符串(例如“Hello”)从堆栈写入标准输出?也就是说,没有数据段。
void main() {
__asm__(
"movl $0x4, %eax \n\t"
"movl $0x1, %ebx \n\t"
// put "Hello" on the stack and load its address into %ecx
"movl $0x5, %edx \n\t"
"int $0x80 \n\t"
"movl $0x1, %eax \n\t"
"movl $0x0, %ebx \n\t"
"int $0x80 \n\t"
);
}
提前致谢
how can i write a string (eg. "Hello") to stdout from the stack? without, data-segments, that is.
void main() {
__asm__(
"movl $0x4, %eax \n\t"
"movl $0x1, %ebx \n\t"
// put "Hello" on the stack and load its address into %ecx
"movl $0x5, %edx \n\t"
"int $0x80 \n\t"
"movl $0x1, %eax \n\t"
"movl $0x0, %ebx \n\t"
"int $0x80 \n\t"
);
}
thanks in advance
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
答案 1:
答案 2:
使用 gcc,第二个答案似乎会生成以下内容:
显然仅使用堆栈。
Answer 1:
Answer 2:
With gcc the second answer seems to generate the following:
which clearly only uses the stack.
我不明白堆栈部分。为什么不使用“movl %0,%%ecx”?
I don't understand the stack part. Why dont't use `movl %0,%%ecx'?
大致意思是:
不能更精确了,因为我不太了解 GCC 内联 asm 和 x86 ABI。
Something along the lines:
Can't be more precise as I'm not very up-to-date on the GCC inline asm and x86 ABI.