On-chip memory built out of M4Ks can be initialised when the PLD is configured.
By default the initialisation file is stored in the same directory as the PTF file - edit your on-chip ram component to find out the name of the file for your particular memory.
If you store anything into an on-chip memory then the IDE will write the appropriate contents into the correct file so that next time you compile a design in Quartus II it will store the software into the on-chip memory. You can select incremental compile to speed up this recompile if the hardware hasn't changed (Quartus II will skip the synthesis and routing stages and just do the final stage of assembling all the data to create the PTF file).