All I am ever told is that the ONLY way to do multiprocessing in the assembly language is to use the OS system calls, making it seem impossible to do it from the assembly language. But let's say I was making my own operating system. How would I use the assembly language to use multiple processers? I know it's possible or else no computer would be able to do it. I just don't know how to do it nor can I find any good rescources for this.
Asked
Active
Viewed 1,378 times
2
-
1It's in Intel Manual 3A chapter 8 – harold Jun 16 '13 at 15:39
-
Is there any assembly examples i can look at that implements this? That would be a great rescource :) And thanks for that manual. I didn't know that Intel had those rescources :S lol – Firstpick5 Jun 16 '13 at 16:28
-
I don't know of any examples specifically showing this, but I suppose you could look at an open source kernel – harold Jun 16 '13 at 16:40
-
Do you think Linux would have any assembly based kernels? – Firstpick5 Jun 16 '13 at 16:48
-
I'm surprised that this has not been already closed as 'too broad'. – Martin James Jun 16 '13 at 17:01
-
Why do you think it's too broad? I just wanted to know how to do multithreading and stuff similar to that in assembly :P – Firstpick5 Jun 16 '13 at 20:07
-
You seem to be mixing up two different things. Applications working under OS must use syscalls because only OS can have full access to multiprocessing control. You can still use syscalls from assembly if you write application. If you write OS, then you will use processor multithreading-features that do hardware task switching. Then if you want you can give applications for your OS access to multiprocessing, just add your own syscalls that will relay (controlled) access to those processor features to them. – j_kubik Jun 17 '13 at 03:13
-
This makes much more sense to me now xD – Firstpick5 Jun 17 '13 at 05:57
-
Hold on, is this a question about multithreading and possibly processes, or about using multiple processors? I interpreted "multiple processers" as meaning the last thing, but it seems that no one else has – harold Jun 17 '13 at 07:02
-
I meant it as using multiple processors... but in order to do that, you would need some threads so really all the stuff kinda goes together. But all I really want to know is how to use multiple processors. If that helps any... :) – Firstpick5 Jun 17 '13 at 19:10
1 Answers
1
Basically you need to setup an interrupt timer, which fires every N intervalls. In this you save the CPU state, like registers and flags, load the new set from a different task and let it continue. This is the easy part of a scheduler. :)
If you want to really do multiprocessing, in full detail, then you should really look into the sources for i.e. Linux kernel.

Devolus
- 21,661
- 13
- 66
- 113
-
I do believ however that the Linux Kernel is written in the C programming language... :/ Is there a way I could like change the C code to Assembly while compiling it? – Firstpick5 Jun 16 '13 at 20:26
-
Of course you can translate it to ASM. That's what the compiler also does. :) Your question is a bit vague though, so it's hard to give a proper answer. If you mean just to do some taskswitching, then this is rather easy. I did this in my early days on the DOS platform and even on the C64. The hard part is when it comes down to managing the devices and make them properly behave in all possible situations, or, when doing an OS, doing a proper protected mode setup. An alternate code for looking into, might be ReactOS. Don't know how much assembly there is, but for the boostrapping it's probable. – Devolus Jun 16 '13 at 21:04
-
This stuff is very helpful to me. thanks :) So basically i need to set up a stack with the code segments in it and then point it to the processor that I want the thread to run on... (well for very basic multi processing) and if I want it to all be automatic I would need to set a timer for it. It makes sense to me now :) But that leaves me with one final question; how would I point it to a specific processor? – Firstpick5 Jun 16 '13 at 21:09
-
I never programmed multicore, so I don't know how to set it up. You will have to look to your CPU manual for information as this is rather specific anyway. Here is a thread that explains it a bit, maybe that helps you: http://stackoverflow.com/questions/980999/what-does-multicore-assembly-language-look-like – Devolus Jun 17 '13 at 04:45
-
Thank you :) I did get a download of the entire intel manual thing... it has a good 3251 pages of information about programming with Intel in it :P It ought to be in there somewhere. – Firstpick5 Jun 17 '13 at 05:58
-
An effective preemptive multitasker is a bit more involved than setting up a timer interrupt. Just for a start, all the other hardware drivers can request a scheduling run so that they can make threads that are blocked on I/O ready/running when their I/O requests are complete. Getting that to work on a single processor system is bad enough, multiple processors becomes a nightmare very quickly. – Martin James Jun 17 '13 at 15:44
-
@MartinJames, yes of course, but you still can implement a scheduler for learning purposes, without the need to resort to systemcalls. And as I already mentioned, when you want to make something more out of it, you have to deal with all the problems involved. – Devolus Jun 17 '13 at 15:50
-
@Devolus: the OP requested information that was relevant to executing on more than one processor or core. The OP specifies not only multi-processing but also multi-processor. Your answer is way too simple: it is valid only for a single-processor situation. The really tricky part concerning additional cores you magnanimously hand over to the OP with "look to your CPU manual for information." Should you have answered this question in the first place? -1 from me. – Olof Forshell Jun 23 '13 at 15:18