Hi,
The CPU accesses memory according to a distinct hierarchy. Whether it comes from permanent storage (the hard drive) or input (the keyboard), most data goes in random access memory (RAM) first. The CPU then stores pieces of data it will need to access, often in a cache, and maintains certain special instructions in the register.
Please refer to this document for how it works:https://computer.howstuffworks.com/computer-memory1.htm
Best Regards,
Wesley Li