ngmir
ngmir

Reputation: 498

How do the instruction sequences differ, when seen by CPU vs. seen by the process?

Here's what I could gather so far, potentially oversimplified:

Now I don't really see how that would help me answer the question in the title. Is there, apart from what I mentioned, a conceptual difference I am missing?

Upvotes: 0

Views: 44

Answers (2)

Brendan
Brendan

Reputation: 37232

How do the instruction sequences differ, when seen by CPU vs. seen by the process?

This looks like a homework question where the expected answer depends on whatever was presented before the question was asked.

Random hypothetical examples:

  • if the course talked about out-of-order execution, then the answer might be something like "process thinks instructions happen one at a time in the order given, while CPU knows they don't happen one at a time and don't happen in the order given".

  • if the course talked about lisp machines, then the answer might be "process thinks its instructions are executed, but they're actually interpreted or translated into completely different instructions, and the instructions the process sees are nothing like the instructions the CPU sees"

  • if the course talked about scheduling, then the answer might be "process thinks it's instructions are the only instructions executed but CPU may be regularly switching between instructions streams from many separate processes".

  • if the course talked about SMT, then the answer might be "CPU fetches instructions from 2 (or more?) different processes and shoves them all down its pipeline to be executed, then figures out which instruction came from where at the end; and process has no idea this is happening"

  • if the course talked about virtual memory management, then the answer might be "process thinks instructions that access virtual memory access RAM but CPU might not execute the instruction and might generate a page fault to let OS do a bunch of fancy tricks that the process doesn't know about"

Upvotes: 1

user3344003
user3344003

Reputation: 21647

Memory contains data. How that data is interpreted depends upon how the processor accesses it. The same location in memory can be interpreted as an instruction, integer, character, or floating point.

The only thing that makes a memory location an instruction is that the Program Counter register points to it. The CPU grabs the data at the Program Counter's location. It then executes the instruction. The program counter has to know how long that instruction is and, unless is it is a branch instruction, has to add that length to the PC.

Most processors allow marking memory pages as no-execute/execute.

The linker will set an initial PC value in the executable file. Other than that, there is generally nothing that says "this is instructions."

Upvotes: 1

Related Questions