【问题标题】:How to use use as in linux with assembly language如何在带有汇编语言的 linux 中使用 as
【发布时间】:2013-05-06 03:20:10
【问题描述】:

我正在学习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

我是这样使用as的
"as -o callee.o callee.s"

编译它,但它失败并显示类似这样的消息
“callee.s|5| 错误:'push' 的后缀或操作数无效”

【问题讨论】:

标签: linux assembly kernel


【解决方案1】:

您可能使用的是 64 位计算机,因此您的 as 默认为 64 位。由于您有 32 位代码,因此您想使用:

as -32 -o callee.o callee.s

【讨论】:

    猜你喜欢
    • 2017-01-26
    • 1970-01-01
    • 2014-12-08
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-07-23
    相关资源
    最近更新 更多