Qbasicnews.com

Full Version: Question about registers
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Pages: 1 2 3 4
Say you write a utility in assembly, which, (like almost every assembly program) uses the EAX register. Fine. But what I don't understand is, surely Windows uses the EAX register as well, to display the GUI, and to do background operations. But what if you need the register, Windows needs the register, and some other processes/programs running in the background need the EAX register? Or any register! I might do:
Code:
MOV EAX,01h
And Windows might have put 0Fh there for another purpose, earlier. But I overwrote that! Surely that would mess it up...
So how does that work?
uhh....hence multitasking Wink
What? Virtual registers?
Nope.

Multitasking doesn't mean doing several things at the same time, but sharing processor time.

You just have your processor, so if you have to do 10 tasks you just divide the time assigning a small amout of time to each task. The system is complex, with priorities, interruptions and many things (in my career it is the most difficult subject Big Grin). But think about it as that you have a queue with all the tasks waiting to use the CPU. The first enters, works with the CPU during a small amount of time, then exits. Now the second one enters while the first one goes to the end of the queue.
Gotcha. So that's all managed by the CPU? Or by the OS?
The OS does the controlling, the cpu just sits there and takes instructions. Smile
:o I think I can now fully appreciate just how brilliant the Windows/Linux people are.
Each running process has a context, which stores information such as the registers, memory map and process id. The operating system is responsible for scheduling processes, when a process is scheduled out the OS saves its context somewhere in memory, the context is then restored when the process is rescheduled.

Register values often need to be saved when doing function calls within a single process also. Function calls often cause several register values to be pushed onto the stack, the called function can now overwrite and use those registers because the old values can be popped from the stack when the function returns.
And what exactly are processes? *Presses CTRL+ALT+DEL on a Win/XP machine* IEXPLORE.EXE is a process? :o
Well, a process is everything it's running. The OS Kernel, the graphics... Every program, your favourite game...
Pages: 1 2 3 4