简体   繁体   English

如何使用汇编语言在linux中使用

[英]How to use use as in linux with assembly language

I am studying Linux kernel, so I have to read some assembly code. 我正在研究Linux内核,所以我必须阅读一些汇编代码。 Here is a sample code 这是一个示例代码


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

I use the as in this way 我以这种方式使用as
"as -o callee.o callee.s" “as -o callee.o callee.s”
to compile it,but it fails with a message saying something like this 编译它,但它失败了一条消息说这样的事情
"callee.s|5| Error: suffix or operands invalid for `push'" “callee.s | 5 |错误:后缀或操作数对于'push'无效”

You're probably on a 64-bit machine, so your as defaults to 64-bit. 你可能在64位机器上,所以你as默认为64位。 Since you have 32-bit code, you want to use: 由于您有32位代码,因此您希望使用:

as -32 -o callee.o callee.s

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM