I think you’ll want to know how the computer works with the code.
The exact way the operating system loads an executable despende d and which operating system we are talking about. The executable format itself also depends on.
Virtual memory
In modern Oses there is a virtual memory system. When a command loads an executable it usually maps the file to memory. So somehow it doesn’t matter much what’s in the mass storage system or the RAM. Of course it needs to be in RAM to run, but when the content will go into RAM is determined by the need and algorithms implemented in the operating system. Loading is done in pages with size 4KB (the most common).
Virtual addresses are provided by the operating system. Actual addresses are provided by the processor. Every modern high-capacity processor has a virtual address translation subsystem for physicists that does not impose cost on normal processing.
All this can be best seen in another question here.
Transference
The copy is made by another operating system service that interacts with the file system and the driver which understands how to command the disk system or other form of "permanent" storage. Obviously it depends on the collaboration of the main processor or some secondary one that makes the control of the input and output devices and the memory (DMA).
When the charge is made it is possible to go delivering the instructions to the processor.
Relocation
The load usually implies hitting addresses other than global symbols. The code works with relative addresses. He doesn’t really know where he’ll actually be in his memory. Knowing the relative addresses you can get the absolute of all symbols and the OS is responsible for relocating the addresses.
Payload
Of course, the executable doesn’t just have instructions. There is a lot of information that helps the operating system decide how to work with that, which configures how it will need to work, among other things.
There are static data. The most common example is text (strings) present code. But in fact virtually any literal will be in any way either next to the instructions or in the static area.
There may also be data that is not directly accessed but is required for the application. Actually you can stick anything in the executable :)
Before starting execution a memory area is reserved for the stack and the heap begins to be formed, if necessary, almost always is. But this has more to do with the process as a whole, because each thread new will have its own stack.
Completion
Anyway, simply put. You can write a book about it. New specific questions can be asked.
If you want information about the electronic operation of the transfer, here is not the most suitable location. If you want something more detailed, you need to see what and in what OS.
Addendum
The term Assembler is often misused. In fact there was not even to use Assembler, nor Assembly, is machine code even.
Your flow is a little crooked. But regardless of this, the instructions are executed one after the other, who has the job of "knowing" which address the next instruction is the processor and not the OS.
– Jéf Bueno
Crooked as so? , I know the instructions are executed sequentially. What I’d like to know is how does the processor know to execute instructions from the "x" memory position? Someone should ask him to do it, right? , I imagine so because after the execution command the stream passes through the S.O kernel before going to processor.
– Canatto Filipe
He knows this because he has a recorder that is always pointing to the memory position that is the next instruction.
– Jéf Bueno