[CS] Computer hardware architecture, a software developer should know
CPU, Memory, and Disk
Von Neumann architecture
For now, computers are almost built on the basis of Von Neumann architecture.
All data and instruction/program are stored in memory. Register in CPU access data and instruction/program from memory. CPU decoding an instruction/program, getting the operands, computing the result, writing the result back to memory.
Not just repeating, all threads/processes run concurrently. For instance, modern CPUs have multiple instructions/program going on at the same time, in independent arithmetic units, or in the general instruction pipeline. The next instruction is not started when the last one finishes, no, it’s done speculatively, overlapping with the current one. Besides, memory is slow, and so it needs things like caches and TLB to store data closer to the processor that may be needed later, or prefetch streams to retrieve data speculatively.
Memory vs. Disk
The memory above, where CPU read from and write into, is the main memory.
Main memory(volatile memory), in contrast to Disk(non-volatile memory), requires power to maintain the stored information; it retains its contents while powered on but when the power is interrupted, the stored data is quickly lost.
Even though the to-be executed/executing programs and data are stored in the main memory, the main memory copied those programs and data from disk after computer turns on.
Besides, the speed CPU access data in memory is 100 times faster than speed CPU access data in disk directly. That’s also the reason why it needs things like register and caches to store data closer to the processor that may be needed later. (registers are located within CPU, caches are bridged between CPU and main memory).