0
$\begingroup$

I don't know whether it is RAM or cache; I can say that isn't the registers since their memory capacity is very small.

$\endgroup$
2
$\begingroup$

It's the RAM.

But further, in order to enhance speed, the CACHE stores a shadow of the RAM content, so it may hold a copy of the program as well (similarly, the RAM has a copy of the program that previously was stored on the hard-drive).

Eventually, parts of the code goes into the CPU and gets stored in one of its registers (not the general purpose ones, but rather some designated registers you have no access to; just think about them as flip-flops). From that point, the program is being executed, one instruction at a time, by the CPU hardware.

$\endgroup$
2
$\begingroup$

This is a very ambiguous question. The whole program will be stored on a local hard drive or a remote server or some other secondary storage device such as a flash drive. At run time some part of the program will be copied into RAM, but not necessarily the whole program. It is the job of the operating system to make sure that RAM contains a copy of the next set of instructions or data that the program needs - this task is called "memory management" or "paging".

From RAM or "main memory", individual instructions will then be copied into instruction cache memory, into a series of pipelining buffer registers and finally into the instruction register which holds the instruction that is currenttly being executed.

$\endgroup$
1
$\begingroup$

A program will remain in secondary memory (HDD) is not running or in Primary memory (RAM, CACHE) if ran recently or expected to run. A program that is being executed is called a process. For every process, a Process Control Block is created and kept in primary memory (RAM). The PCB contains pointers to the start and the current line in the program to be executed .

$\endgroup$
1
$\begingroup$

Your question doesn’t make sense. There is no “memory” dedicated to holding “the copy of the program to be executed”.

On a modern computer there isn’t one program to be executed. Normally I have a dozen or two programs running at the same time.

Each program is stored on the hard drive, SSD drive or flash drive. The OS assigns address space to the program, then the whole program is mapped to that address space. At that point, none of the program is in RAM. As instructions are to be executed, the OS automatically loads those instructions into RAM. Cache memory holds copies of the least recently used data in RAM. Instructions are removed from cache or RAM if they have not been used for a while.

Summary: It’s all over the place.

$\endgroup$
1
  • $\begingroup$ Thanks for your valuable answer, I completely agree with your point, but I need more clarification in the cache and I want to know whether it holds the copy of recently used data or it holds the data which is going to be used. $\endgroup$ Jul 8 '19 at 15:14
-2
$\begingroup$

The whole point of the Von Neumann architecture is that programs and data are treated in the same way. So the answer to your question is that the registers, cache, main memory and backing store are used in exactly the same way as they would be for any other data.

$\endgroup$
3
  • 1
    $\begingroup$ The OP didn't ask about specifically the von Neumann architecture though. And modern processors have a dedicated instruction cache so it's not 'exactly the same'. $\endgroup$
    – orlp
    Jul 7 '19 at 15:27
  • $\begingroup$ @orlp Name a computer that uses any other architecture. $\endgroup$ Jul 7 '19 at 15:37
  • $\begingroup$ ARM for example requires special instructions to flush the pipeline and instruction cache in case you use self-modifying code - regular memory access would bypass the cache invalidation mechanisms because there aren't any for code precisely because code is handled differently than data. $\endgroup$
    – orlp
    Jul 7 '19 at 15:56

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.