I like to do some optimisation and so I like to substitute a line of c code with 2 lines of assembler.
rb->am += N
the ringbuffer struct rb gets incremented by an variable N
I am struggling to get the asm right. Here comes my pseudo code
void myFunc(struct rb, const uint16_t N)
...
asm(
"mov w0, %0\n"
"add %1, w0"
: rb->am
: N
: w0
);
If I understand the asm keyword its
asm(<instruction> : <input operants> : <output operants> : <clobbers>)
I am currently don't know how to get the syntax right.
W0 is a register. I assume that I need to tell my compiler that I am using that.
rb->am needs to be resolved into a memory address.
N is a function parameter (like rb).
Any idea how to get this right?
[update] The target platform is a dspic33 from microchip. I looked up the programmer manual. The only ADD that alters a uint16 variable at the RAM is working against the W0/WREG.
ADD f {,WREG} -> Destination = f + WREG
Smth like (my pseudo code)
MOV WREG, N
ADD addr(rb->am)
is needed. Here a link to my source https://ww1.microchip.com/downloads/en/DeviceDoc/70000157g.pdf
Solved:
Note:
Thx for the fast and good answers