4

I'm learning ASM and I have a small problem. I can't "declare" more than one string in "section.data". I'm trying something like this:

section .data
    string1 db "test1 ", 0;
    string2 db "test2 ", 0;
section .text
    global _test
    extern _puts
    _test:
         lea rdi, [rel string1]
         call _puts
         lea rdi, [rel string2]
         call _puts
         ret

This function is supposed to print "test1 test2 " on STDOUT, but it doesn't work. The result is:

test2

It only works for the last string stored! If someone know why, please tell me!

Ross Ridge
  • 38,414
  • 7
  • 81
  • 112
Hugo Hismans
  • 173
  • 1
  • 1
  • 8
  • 2
    Let me guess... Nasm-2.11.08? It has a bad bug with `-f macho64`. Go back to 2.11.06. 2.11.09 should be along soon and should fix it... if all goes well. These things happen... :( – Frank Kotler Jun 13 '15 at 04:11
  • @FrankKotler - this is arcane knowledge. An (expanded?) answer might help others. – Brett Hale Jun 13 '15 at 07:52
  • I haven't been "active" as a developer for quite some time, but I'm still on the list. Scroll down a bit here and there's some explanation of what went wrong. http://sourceforge.net/p/nasm/mailman/nasm-devel/ – Frank Kotler Jun 13 '15 at 15:39

1 Answers1

2

If you're using nasm 2.11.08, there is a issue documented here to do with relative addressing combined with multiple entries in the data section.

You can do one (or both) of two things to be certain.

First, you can have a look at the generated assembler code to investigate what it's actually churning out. That's probably the definitive option since you can then see exactly what the CPU will be running.

Second, you can test your code with an earlier release of nasm to see if the problem goes away. If so, that's indirect evidence that it's the bug in 2.11.08 causing your issues.

paxdiablo
  • 854,327
  • 234
  • 1,573
  • 1,953