They are written by other instructions. An example program made of 4 instructions could be:
- put the number 5 in register 3
- put the number 6 in register 7
- add register 3 and register 7; store the answer in register 2
- put the number in register 2 in memory address 1234
I am speaking in general, not specifically about RISC-V. Maybe on RISC-V, step 4 actually takes two instructions, as it does on some CPU types.
When a number occurs directly in the instruction we can call it "hard-coded" although a more technical term is that it's an "immediate value". Values can also come from other places, e.g.:
- put the number from memory address 12345 in register 3
- put the number 2 in register 7
- Bitwise-AND register 3 and register 7; store the answer in register 2
- If the number in register 2 isn't zero, then go to step 27.
and maybe memory address 12345 is hardwired to connect to the keyboard. It is typical that CPUs connect to the outside world by using special memory addresses that connect to things that aren't memory.
mov
or sometimesld
. \$\endgroup\$