Do computers execute instructions one after the other or does it jump around the program and not execute instructions one after the other?

Home » Programming & Design » Do computers execute instructions one after the other or does it jump around the program and not execute instructions one after the other?
Programming & Design No Comments

please help this is probably a simple computer science question but i don't know thanks

When a computer runs a program, it executes one instruction at a time, one instruction after another.
OR
When a computer runs a program, it makes decisions. So the computer jumps around the program and doesn't execute

please help this is probably a simple computer science question but i don't know thanks

When a computer runs a program, it executes one instruction at a time, one instruction after another.
OR
When a computer runs a program, it makes decisions. So the computer jumps around the program and doesn't execute the instructions one after another.

Best Answer:

?: It does both but with a certain amount of order. The CPU automatically goes to the next instruction in memory. It simply fetches the first instruction and executes that then automatically increments the instruction pointer to the next memory location. However, it may come across a jmp (jump) instruction which will tell it to jump to some other location. There it will execute instructions again one after the other in sequential order. But it is very common for a call instruction to take place, which is like a jmp instruction, except that it stores the current location in memory to recall later before jumping to the new location. Then at the new location a return statement will be encountered which causes another jump back to where it originally came from. This is called a subroutine.

So a computer does both, it runs instructions one after the other then stops and goes elsewhere and runs instructions one after the other then stops and then goes somewhere else and runs instructions one after the other.

Other answer:

?:
Hi, Peggy,

It's hard to know how to interpret this question, but at the level that you are probably studying things — focusing on the program that YOU are writing — a computer executes instructions one after another UNLESS there is a reason to jump.

maxw = 150
weight = input ("Enter weight: ")
if weight < maxw:
…. print ("Good job")
…. points += 3
else:
…. print ("You need to try harder")
…. points -= 1
print ("See you tomorrow")

Depending on the weight entered, either the 2 lines after the if will be skipped or the 2 lines after the else will be skipped.

But, even if the computer has one processor, the operating system can execute an "interrupt" and be doing things it needs to do behind the scene and then return to your program.

If you have been studying interrupts, then your answer needs to reflect that. Otherwise, you aren't expected to know about such things.

CarolOklaNola:
That depends entirely on how multiple computer programs are coded. one computer program can 'trigger a lot of other computer programs, but it's NOT random..; I've programmed so many endless computer loops in three computer programming classes that i know how to get out of them fairly quickly. My first programming class was FORTRAN IV in Simmer 1974.. My last one was MAT-LAB in fall 2001.. ALL those HOURS of punching cards in freezing computer labs..
Them:
Runs a code – which is one operation after another. But now we have central processing units which work in parallel…… so it's running code in two or three or four streams simultaneously.

And that's about all I can guess about how this thing works.

LEAVE A COMMENT