NASM issue on OSX 64-bit

694 views Asked by At

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!

1

There are 1 answers

0
paxdiablo On BEST ANSWER

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.