1

I am studying Linux kernel, so I have to read some assembly code. 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 -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'"

user1198331
  • 139
  • 2
  • 3
  • 10
  • Near duplicate: https://stackoverflow.com/questions/36861903/assembling-32-bit-binaries-on-a-64-bit-system-gnu-toolchain, which talks about `gcc` and `ld`, but not `as`. (You can use `gcc -m32 foo.S` to assemble and link.) – Peter Cordes Sep 29 '17 at 04:34

1 Answers1

3

You're probably on a 64-bit machine, so your as defaults to 64-bit. Since you have 32-bit code, you want to use:

as -32 -o callee.o callee.s
Carl Norum
  • 219,201
  • 40
  • 422
  • 469