Problem with AVR ASM - can't get a command working

Hi, AVR newbie here,

I'm trying to convert some little C commands to ASM, mostly for training, and I encountered a big ununderstanding. Why is that working :

//vx[curEntry.read()] = curEntry.read();
        asm volatile (
        "\n\t"
        "mov %0, %1\n\t"
        : "=&r"(vx[curEntry.read()])
        : "r"(curEntry.read())
        );

And not this :

//vx[curEntry.read()] += curEntry.read();
        asm volatile (
        "\n\t"
        "add %0, %1\n\t"
        : "=&r"(vx[curEntry.read()])
        : "r"(curEntry.read())
        );

What am I doing wrong ? It does compile but doesn't do what is expected.

In one case, you are moving a byte from one location to another. In the other case you are adding a byte from one location to another. Without knowing the type of the variables in the commented out statement are, we can only guess why one works and one doesn't. If vx is an array of Strings, then + is a concatenation operator, not an addition operator.

vx is an array of 16 byte variables. It is initialized before this ASM codelet is encountered.

byte vx[16];
// stuff
for(i = 0; i < 16; i++) vx[i] = 0;

It does compile but doesn't do what is expected.

Hi, Mr. Mechanic. My car is making funny noises sometimes. Fix it please. No, i don't have time to have you listen to it now. Just fix it.

If you don't tell us what you expect, or what the code actually does, can you reasonably expect help? No, you can't.

Hence the comments.

The first one is intended to read a byte from curEntry (FILE*) and store it to vxcurEntry.read(), the latter being read first. The ASM code does work.

The second one is intended to add curEntry.read() to vx[curEntry.read()], the latter being read first. The ASM code does not work on this one, but I have no idea on what it actually does.

I'm not sure what you expect the code to do. Generally, it is not normal to mix C++ method calls with assembler. Why are you doing it?

I'm programming on the Esplora, and have very little space left out of the available 28kb (less than 1kb). So I'm trying to spare as many single bytes as possible by rewriting micro-operations like this in ASM.

I think you will find that the compiler will do it better.

How many bytes does it take to refer to "vx[curEntry.read()]"

The compiler is smart enough to stash it in a register if it is invariant.