R__
R__

Reputation: 1531

Why this doesn't compile?

I copies it from here but compile fails:

[root@ test]# gcc -c test.S
test.S: Assembler messages:
test.S:8: Error: suffix or operands invalid for `pop'
[root@ test]# cat test.S
.text
    call start
    str:
        .string "test\n"
    start:
    movl    $4, %eax
    movl    $1, %ebx
    popl     %ecx
    movl    $5, %edx
    int     $0x80
    ret

Why?

OS:

CentOS release 5.5 (Final)
Kernel \r on an \m

Upvotes: 0

Views: 261

Answers (1)

karlphillip
karlphillip

Reputation: 93410

If you read that question again carefully, you'll notice that the user has written an application to load this code, which has been previously compiled into it's binary representation, at runtime. The code itself is not a full application. This code as it is, cannot generate a valid binary (executable) application.

When writing assembly code you have a few options as for what compiler and syntax you can use to write your programs. If you are interested in learning assembly, I recommend reading Programming from the Ground Up.

The example below came from here:

.section .data
hello:
   .ascii "Hello, World!\n\0"

.section .text
.globl _start
_start:
   movl $4, %eax
   movl $14, %edx
   movl $hello, %ecx
   movl $1, %ebx
   int $0x80
   movl $1, %eax
   movl $0, %ebx
   int $0x80

Compiled with:

as hello.s -o hello.o
ld hello.o -o hello
./hello
Hello, World!

Upvotes: 2

Related Questions