With regards to introductory (beginner) Von Neumann computer architecture, how does a program change the order in which instructions are executed?
I know the control unit is responsible for retrieving the instruction from memory and then decodes and executes the instruction. Their connected by a bus. The control unit and ALU are together in the CPU.
I'm guessing different lines of code are stored in different addresses in the RAM?
Is it a easy question, and I'm just thinking its difficult?
Asked By : David G
Answered By : Yuval Filmus
You are getting into to much detail. You can think of a CPU as some kind of automaton which operates roughly as follows (ignoring pipelining). There is a register called (in x86) IP (Instruction Pointer). The CPU operates an infinite loop (ignoring interrupts):
Read the instruction $\iota$ at address IP; determine its length $\ell$, and increment IP by $\ell$.
Execute $\iota$; this might change IP.
Go back to 1.
This is implemented in some sophisticated way, but if you don't care about performance, it performs as if the CPU was actually running this infinite loop. Control instructions change IP and so control which instructions are executed.
Different programs are just collections of instructions. When you run a program, the operating system loads it into memory and then jumps to the first instruction (i.e., sets IP to the address of the first instruction). From there on, the program executes until it terminates and releases the token back to the operating system. (Modern operating systems, which are multitasking, are more complicated, but DOS ran much according to this description, ignoring interrupts.)
Best Answer from StackOverflow
Question Source : http://cs.stackexchange.com/questions/23829
0 comments:
Post a Comment
Let us know your responses and feedback