flat assembler
Message board for the users of flat assembler.

Index > Main > [SOLVED] Are registers shared between programs?

Author
Thread Post new topic Reply to topic
Apos



Joined: 11 Jan 2012
Posts: 17
Location: Paris, France (I'm not from France though.)
Apos
I've just started in Assembly and one thing I see on different sources is that it seems like there is a limited amount of registers. If there are many programs running at the same time, I'm guessing they are all using them at the same time? Is that taken care of by the operating system?

(I have made two little programs run at the same time and try to capture data from each other but it didn't work...)(Using Sleep...)

_________________
"A designer knows he has achieved perfection not when there is nothing left to add, but when there is nothing left to take away." - Antoine de Saint-Exupéry


Last edited by Apos on 13 Jan 2012, 14:57; edited 1 time in total
Post 13 Jan 2012, 02:15
View user's profile Send private message Reply with quote
typedef



Joined: 25 Jul 2010
Posts: 2913
Location: 0x77760000
typedef
you mean at runtime ?
Post 13 Jan 2012, 02:28
View user's profile Send private message Reply with quote
Apos



Joined: 11 Jan 2012
Posts: 17
Location: Paris, France (I'm not from France though.)
Apos
Yeah, at run-time. (While programs are running.)

(Programs can use registers while they are not running?)

(If you mean the little programs, I was loading a character into a register using program A (And making it wait) and tried to print out what was loaded in the register with program B while A was still running. B would fail and A would be able to print the right character after the wait.)(This was just as a test before asking the question on here.)

_________________
"A designer knows he has achieved perfection not when there is nothing left to add, but when there is nothing left to take away." - Antoine de Saint-Exupéry


Last edited by Apos on 13 Jan 2012, 14:56; edited 1 time in total
Post 13 Jan 2012, 02:30
View user's profile Send private message Reply with quote
Tyler



Joined: 19 Nov 2009
Posts: 1216
Location: NC, USA
Tyler
It's something that's taken care of by the operating system when it switches from one task to another. It stores the values of the registers set by the current task into memory and loads the values previously set by the next task into the registers from memory.

As far as anything concerning other tasks, for programs, it is all taken care of by the operating system. It keeps their memory and everything else separate. From the perspective of a normal program, it's almost like they're the only program running on the computer.
Post 13 Jan 2012, 03:06
View user's profile Send private message Reply with quote
typedef



Joined: 25 Jul 2010
Posts: 2913
Location: 0x77760000
typedef
Apos wrote:
Yeah, at run-time. (While programs are running.)

(Programs can use registers while they are not running?)

(If you mean the little programs, I was loading a character into a register using program A (And making it wait) and tried to print out what was loaded in the register with program B while A was still running. B would fail and A would be able to print the right character after the wait.)(This was just as a test before asking the question on here.)

Well then I would be able to hack online games easily by making an application and modify some registers so that all other applications get affected.

You see the logic there ?
Post 13 Jan 2012, 04:51
View user's profile Send private message Reply with quote
DOS386



Joined: 08 Dec 2006
Posts: 1901
DOS386
Almost nothing is shared ... because the multitasking OS isolates the apps from each other Shocked
Post 13 Jan 2012, 08:39
View user's profile Send private message Reply with quote
Apos



Joined: 11 Jan 2012
Posts: 17
Location: Paris, France (I'm not from France though.)
Apos
That's good to know. I was worried that some of the values I put in the registers could end up being changed without my program knowing.

_________________
"A designer knows he has achieved perfection not when there is nothing left to add, but when there is nothing left to take away." - Antoine de Saint-Exupéry
Post 13 Jan 2012, 14:51
View user's profile Send private message Reply with quote
shutdownall



Joined: 02 Apr 2010
Posts: 518
Location: Munich
shutdownall
Depends on the cpu mode used by the OS. In Real Mode memory areas (and registers) are not safe for use of other programs. Anyway programs normally respect this private area but its not really protected.

In Protected Mode this is done by the CPU itself, operating system only does a general configuration. This is the main goal of the protected mode to do all activities by the cpu itself from hardware and not via software when switching between tasks. Wink
Post 15 Jan 2012, 01:27
View user's profile Send private message Send e-mail Reply with quote
Tyler



Joined: 19 Nov 2009
Posts: 1216
Location: NC, USA
Tyler
shutdownall wrote:
In Protected Mode this is done by the CPU itself, operating system only does a general configuration. This is the main goal of the protected mode to do all activities by the cpu itself from hardware and not via software when switching between tasks. Wink
Except that most protected mode OSes, or at least Windows and Linux, don't use hardware task switching (the TSS). (I'm not sure about Windows, but it probably does, because the consensus is that hardware task switching is slower.) They use software task switching, which is just some kind of interrupt gate that does the work of hardware task switching. Razz
Post 15 Jan 2012, 04:43
View user's profile Send private message Reply with quote
shutdownall



Joined: 02 Apr 2010
Posts: 518
Location: Munich
shutdownall
I don't think so. If you use software task switching it is in my opinion impossible to protect memory areas of different processes against each other. So one of the main features of the protected mode (the other one is memory addressing and paging) is lost. If I am wrong, please correct me. Rolling Eyes
Post 15 Jan 2012, 12:21
View user's profile Send private message Send e-mail Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 17467
Location: In your JS exploiting you and your system
revolution
shutdownall wrote:
I don't think so. If you use software task switching it is in my opinion impossible to protect memory areas of different processes against each other. So one of the main features of the protected mode (the other one is memory addressing and paging) is lost. If I am wrong, please correct me. Rolling Eyes
Yes, you are wrong. Consider this me correcting you. Wink Memory and paging are entirely independent of task switching by the OS. The OS can choose to protect your code, or not, no matter whether hardware or software task switching is used.
Post 15 Jan 2012, 12:46
View user's profile Send private message Visit poster's website Reply with quote
cod3b453



Joined: 25 Aug 2004
Posts: 619
cod3b453
The software switch can perform (most of) the same state swapping; the protection aspect is provided by the page tables and other memory settings. The IOPB is unlikely to be changed across user processes, except in the case of user mode drivers.

----

Also some operating systems do-/did- not save the FPU and SSE registers across processes without explicitly notifying the OS first.
Post 15 Jan 2012, 12:55
View user's profile Send private message Reply with quote
shutdownall



Joined: 02 Apr 2010
Posts: 518
Location: Munich
shutdownall
I read a book about real time OS'es which explained the facilities of protected mode and I thought this would be used in this way. So I am a bit surprised that this is not reality. Anyway I can imagine that it's possible to do this internal by software, choose privilege level 3 and some memory limits when giving control to a task and just give control to other task when interrupted and save registers manually.

In fact I did not do much with protected mode by now. How much faster is this in practice not to use hardware task switching ? I thought at leest Microsoft would use it this way. But you never learn out. In fact it's not very different to old DOS TSR switching. Rolling Eyes
Post 15 Jan 2012, 12:58
View user's profile Send private message Send e-mail Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 17467
Location: In your JS exploiting you and your system
revolution
IIRC Windows uses software task switching. Or at least the older versions did, for performance reasons. Although that may have changed now with newer processors and newer OSes. However, I really doubt there is any perceivable or measurable difference with CPUs being vastly faster now, the amount of time spent task switching is a very tiny fraction of total run time, and most of that task switching time would be spent reading/writing saved values to/from the slower memory.
Post 15 Jan 2012, 13:05
View user's profile Send private message Visit poster's website Reply with quote
Display posts from previous:
Post new topic Reply to topic

Jump to:  


< Last Thread | Next Thread >
Forum Rules:
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Copyright © 1999-2020, Tomasz Grysztar. Also on YouTube, Twitter.

Website powered by rwasa.