Yes. Programs and data are both in main memory when they are active.
Say that a light bulb is controlled by a processor running a program in main memory. The controller can turn the light bulb fully on and fully off, can brighten or dim the bulb (but not beyond fully on or off.) The machine instructions are one byte long, and correspond to the following machine operations:
|Turn bulb fully on
|Turn bulb fully off
|Dim bulb by 10%
|Brighten bulb by 10%
|If bulb is fully on, skip over next instruction
|If bulb is fully off, skip over next instruction
|Go to start of program (address 0)
The bulb is wired so that when the switch is first turned on the instruction at address zero is performed. Then, instructions are performed one at a time, in order, until the "Halt" instruction is encountered or the controller crashes.
The controller crashes if it encounters an instruction not in the table or tries to get an instruction from an address that does not exist.
The A "Skip" instruction checks the brightness of the bulb and possibly skips over the instruction after it.
The "Go back" instruction causes the processor to start again with the instruction at address 0.
Here (let us pretend) is the main memory for the controller:
Click on the light bulb
Change the program currently in memory. Fill in instructions starting at address 0. Copy and paste from the list of machine instructions or directly edit the bit patterns.
Try to alter the program so that the light bulb blinks on and off without stopping. Or, write a program so that the bulb gradually brightens and dims repeatedly.