1
我正在学习Linux内核,所以我必须阅读一些汇编代码。下面是一个示例代码如何使用Linux中的汇编语言
SYSWRITE=4
.globl mywrite,myadd
.text
mywrite:
pushl %ebp
movl %esp,%ebp
pushl %ebx
movl 8(%ebp),%ebx
movl 12(%ebp),%ecx
movl 16(%ebp),%edx
movl $SYSWRITE,%eax
int $0x80
popl %ebx
movl %ebp,%esp
popl %ebp
ret
myadd:
pushl %ebp
movl %esp,%ebp
movl 8(%ebp),%eax
movl 12(%ebp),%edx
xorl %ecx,%ecx
addl %eax,%edx
jo 1f
movl 16(%ebp),%eax
movl %edx,(%eax)
incl %ecx
1:
movl %ecx,%eax
movl %ebp,%esp
popl %ebp
ret
我用的是因为以这种方式
“为-o callee.o callee.s”
编译它,但它失败,提示信息说像这样
“callee.s | 5 |错误:后缀或操作数'推'无效”
Near duplicate:https://stackoverflow.com/questions/36861903/assembling-32-bit-binaries-on-a-64-bit- system-gnu-toolchain,它讨论'gcc'和'ld',但不是'as'。 (你可以用'gcc -m32 foo.S'来组装和链接。) – 2017-09-29 04:34:24