0

I understand that in .data section there are arrays of chars, and last bit of array is null (0). Also, 10 is a code for new line. My question is, why when in .data section I delete 10 and left 0 program won't print anything, but when I delete 0 and left 10 program is working?

global main
extern printf

section .data
gwiazdka db '*',10,0      ;HERE is my question

section .text
main:
mov rbx, 0

petla:
mov rdi, qword gwiazdka
mov rsi, rbx
mov rax, 0
call printf

inc rbx
cmp rbx, 4
jne petla

mov rax, 1
int 80h

I want to build a square from stars and I don't get it why I can't print single chars without starting new line... I compile like that:

nasm -f elf64 program.asm
gcc program.o -o program
./program
rkhb
  • 14,159
  • 7
  • 32
  • 60
Patryk
  • 1
  • 2
  • 1
    You should not use the `exit` syscall, just return from `main` or at worst, `call exit`. Otherwise you won't let the C library flush its buffers so the last line gets stuck in them. Alternatively, use the `write` syscall and not `printf`. – Jester Nov 13 '16 at 02:16
  • @Jester: The [x86 tag wiki](http://stackoverflow.com/tags/x86/info) has a canonical dup-target for these `_exit()`-without-flushing questions (search for "printf") – Peter Cordes Nov 13 '16 at 02:18

0 Answers0