Inline ASM - Advanced AVR 3.0 Core - Finalizing
Inline ASM - Advanced AVR 3.0 Core - Finalizing
Just formatting the code into the page took 6 minutes....If Juno Inline ASM 2.0 is a knife, it's more than sharp enough to cut through steel. It has 15 completely rewritten examples demonstrating almost every aspect of inline asm in c. Yet a knife is useless regardless how sharp it is on a clumsy hand. Instruction is not included in this knife. Even though it's dumb to ask for instruction for a knife, it's not an unreasonable request. One can't really use inline asm in c, unless one is efficient in asm already. A knife is all about cutting, although no one is stopping you from using it as self-defence or mortal combat again your wife. asm in c is about about moving data that normally can't be accessed by c. It would be dumb to use it as self-defence again your wife or any other reason.
PS. Not that I am an expert in mortal kombat or anything, if you feel like your life is threaten, call 911 and run. Domestic violence should not be tolerated in any way, unless your wife is very fat (very rich) and is the owner of an expensive spot car (hard to run away from or out-run).
===================================================
Here is the explanation text for this example shown in the video:
lds and sts instructions requiring a constant input address don't work unless its address is known, so using indirect addressing is probably the only way to address the sRAM via inline asm, so ld and st are the instructions of choice.
This function returns a value, and this is the only example that returns a value because there are better ways to return a value without using return, including this one. The returned value has actually been returned back to sram prior it being returned upon exiting the function, since this function takes a pointer as input.
It may not be obvious, but temp or r24 has been returned to the main function. Defining a local variable for the return is one of the easiest ways. The registers inside the clobber list definitely can't be return, since its values are destroyed upon exiting the function. Likewise, input should not be returned, since by definition, input value are read-only, so the function by definition should not be changing its values, so returning a variable that is read-only and not modified doesn't make any sense.