Hello, sorry if this is a stupid one, I recently started learning assembly and I have read many different tutorials, most of them start with " cpu has 8 main purpose registers... " bla bla you all know that. Ok so cpu has a few registers for programs to use, cool, but on my pc there are like tons of programs running all the time, how is it possible for all those programs use the same few registers without overwriting eachothers data?

correct me if im wrong..from what i learn in assembly ,we use these so called interrupts that is use to interrupt the processor of your computer every time theres a code that wants to process in your computer..i think those are system file need to run for your pc to run smooth..try closing one of them and you'll get an error..i think this is a stupid reply also..

Interrupt requests come from different devices like I/O . But i don't think the processes generate interruptions(except bios functions).

The way cpu's resources are handled is OS' job. The OS allows difrent processes to be executed at _different_ points in time , and not simultaneously. The things is that the fractions of time,given for the processes as permission to use the cpu, are so small that we believe they get executed simultaneously, witch is not true.

The OS comands work like this:
Multitask:
Load segments of a procces (from ram) in cpu.
Execute.
Unload current segments of the current executing process. (save them to ram)
loop multitask

And that's mainly the way it works. Hope that solved your question

As mentioned by Alex_ applications in a multi-tasking
enviroment do not run simultaneously but yield the processor
one at a time.
Each process yields the processor for some predetermined
amount of time and then the registers upon which the
task depends is backed up in the RAM, and the next task's
registers are restored and the task is executed.
This task-switching occurs so quickly that the applications
appear to be running simultaneously.

This is a good question. It shows you are thinking past the pages in the book. The reason so many programs can exist(by exist I mean run) at the same time is -
Modern operating system(multi tasking) will allow running programs to use the processor for a certain amount of time then save the programs environment and switch to the next program.

So if we have three programs

program a
program b
program c

then the scheduler will let "a" run for an allotted time save its environment then load "b's" environment and start executing "b" when "b's" time expires its environment is saved and "c" is loaded and "c" starts executing

Now this loop continues executing program "a" then "b" then "c" then "a" then "b"
until the programs exit or the system goes down.

Note this is a very oversimplified view of what goes on...

Also environment is the executing state of the program...i.e. register values, system values

Wow thanks everyone, so many answers already, I get it now.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.