Writing and changing SRAM/Program memory on the fly.

I know i can read / write to DATA space... what i want to do is read / write directly to PROGRAM / SRAM space.

I know that is where the actual binary of the sketch is stored, the actual program that runs on the Uno

Yes, i know that is dangerious... it is essentialy the program trying to edit its self in run time.. yes I know... i just want to see if I can do it.

So change an "ADIW Z , 3" to say "ADIW Z , 5" and so on.

I just want to see if I can do it. Its just for learning.

My question is if I know the memory address of the assembler opcode for ADIW and the memory address for register Z and the k of 3... what opcode to use to edit it in assembler?

Thank you

Flash/Progmem is the program space.

SRAM space is the 2K where variables and registers and the stack and heap are, all the stuff that changes while a program runs.

See the links at the middle of this page for self writing.

It's like asking for information on shooting yourself in the foot. The program memory is set up that way because literal geniuses worked out that it's better that way. They are even smarter than the guys who worked out that gun barrels should be easy to hold in a way that doesn't point them towards your feet.

You can do it on some Arduinos such as the DUE, which don't have quite the same wall between program memory and user memory like the AVR ones. It's still not a good idea, unless you're writing a bootloader.

Search for threads where people are trying to program their Arduinos over Wifi or SD cards. That's when it becomes useful and not foot-shooty. There's lots of information available there.

All good answers and advice... thanks. MorganS: I think your right. This might be one tree I should nt try to climb.

Thank you all again!