Babkock
Babkock

Reputation: 47

Assembly program is printing newline

So I wrote this simple assembly program. I made hello and world separate for practice.

    .cstring
hello:
    .ascii "hello "
    .text
world:
    .ascii "world\0"
    .text
.globl _main
_main:
    pushl %ebp
    movl %esp, %ebp
    subl $8, %esp
    movl $hello, (%esp)
    call _puts
    movl $world, (%esp)
    call _puts
    xorl %eax, %eax
    leave
    ret
    .subsections_via_symbols

I am running Mac OS X with an Intel processor. This program is printing a newline character every time I call puts. Can someone explain to me why it's doing this?

Upvotes: 1

Views: 314

Answers (1)

Ignacio Vazquez-Abrams
Ignacio Vazquez-Abrams

Reputation: 799450

Because that's what puts(3) does.

The function puts() writes the string s, and a terminating newline character, to the stream stdout.

Upvotes: 3

Related Questions