How does hardware in a PC correlate to software?

664 views

How does ram and a cpu control an OS and vice versa?

In: Technology

4 Answers

Anonymous 0 Comments

How a computer works is a pretty huge topic. I’ll try to explain enough to answer your question at an ELI5 level.

The CPU runs instructions.

The RAM is what holds the instructions themselves, as well as the data the instructions operate on.

It’s convenient for us humans to think in terms of *programs*. A program is a list of instructions that accomplishes a single task.

Some old or simple computers only run one program at a time. But many computer systems today are intended to run multiple programs at once.

If you want to run multiple programs on the same computer, you might think about having a “master program” that gives the computer instructions about how to “split itself up” between the multiple running programs. People usually call that “master program” an OS.

One big example is what we call *cooperative multitasking*. The way this works is that the OS gives the CPU a special instruction which basically says: “Every 1/100 of a second, stop what you’re doing, save the address of the next instruction you would run, and instead run instructions starting at address 995640.” (An *address* is simply a numbered location in RAM, where instructions or data can go.) Well, address 995640 is part of the OS. The instructions there are a complicated subroutine that basically says “Find the next program that’s ready to run, and start executing instructions where it last left off.”

The net effect of this is that multiple programs can “share” the CPU. What if there’s some program that’s running a long calculation that will take many seconds, or has become stuck in an infinite loop? There’s no problem. The OS will take control from the program, and let other programs run, including the programs that respond to user input, and tell the screen how to update drawings of things like windows / buttons. So the system as a whole is still usable even though a particular program is “busy thinking.”

Tech folks often say things like “the OS will take control from the program,” using a kind of high-level metaphor to understand the big picture of what’s happening. The reality is more like this: The CPU is following the instructions the OS gave it ahead of time, to execute a certain piece of OS code every 1/100 of a second. And that piece of OS code is a bunch of instructions that tell the CPU to run instructions from another program.

Saying things like “the OS will X” or “the OS will Y” is a fictional anthropomorphic way of thinking that helps us humans understand the computer’s operation. In fact, the OS doesn’t *do* anything, it’s just a list of instructions. Only the CPU actually *does* something, by executing an instruction. The CPU itself doesn’t “understand” the big picture of what is accomplished by all the instructions of a program, or all the instructions of all the programs currently loaded into RAM. The CPU only needs to understand the instruction it’s currently running, and what RAM address is the next instruction.

You are viewing 1 out of 4 answers, click here to view all answers.