Question

I'm quite new to ASM so please excuse me if the question is too silly. I'm using GAS + Ubuntu 12.04.

I have done the following:

.data
    x:  .ascii "15"

.text

.global _start

_start:
    movl $4, %eax
    movl $1, %ebx
    movl $x, %ecx
    movl $2, %edx
    int $0x80

EndProg:
    movl $1, %eax
    movl $0, %ebx
    int $0x80

The above works fine and outputs 15. But when I try to output it as a long, it shows nothing. And no errors either.

Here's my non-working code:

.data
    x:  .long 15

.text

.global _start

_start:
    movl $4, %eax
    movl $1, %ebx
    movl $x, %ecx
    movl $4, %edx # I'm assuming 4 bytes for long.
    int $0x80

EndProg:
    movl $1, %eax
    movl $0, %ebx
    int $0x80
Was it helpful?

Solution

In order to print a number, you need to compose it to individual characters which make up the number. You can decide whether you want it in decimal, hexadecimal or any other format.

Alternatively, call printf to do it for you.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top