Take the 2-minute tour ×

Can a whole operating system be written without using even one line of C/C++ code?

EDIT: One more to add to the list - assembly

share|improve this question
I'm reminded about the old joke about /vmunix.el –  Paul Tomblin Mar 9 '09 at 17:07
@Rich B - good job editing the question to make all the replies look like their authors didn't read the question. –  Ori Pessach Mar 9 '09 at 17:16
Wasn't there a machine out there that had an OS written in Modula 3 or Ada or some other Bondage and Discipline language? –  Paul Tomblin Mar 9 '09 at 17:24
add comment

11 Answers

up vote 42 down vote accepted

Yes and no.

First of all, it's important to remember that whatever your language of choices, in the end the compiled product is in assembly language (or more accurately, machine code). Even interpreters (such as the cpython interpreter) are ultimately translating your scripts into machine code.

But that's probably being overly technical and missing the heart of your question:

"Can I write an operating system in a higher-level language?"

The answers to this are both personal and technical.

First, the personal side: if don't already know how to write an operating system in a mix of assembly language and C then you have absolutely no business trying your hand at OS design.

Often those new to programming have these sorts of questions because they want to do something as cool as writing a new OS without all the learning required to even attempt such a project. They wonder if higher-level languages can be a way to bypass all that messy study.

So if, in your heart-of-hearts, this is what you're after, stop now. Stop, stop, stop. Becoming good at something is hard work. There are no shortcuts. Be ready to roll up your sleeves and get some carpal tunnel syndrome.

That doesn't preclude following a path to eventual OS design! If that's your passion, then start at the top and work your way down. Get books on networking protocols, memory management, threading, etc, tackle each major subsystem and get to know it well. You can't write a new one if you can't use an old one!

Then read books on operating system design and implementation until you dream about process management methodologies.

Just bear in mind, the amount of knowledge necessary (not just of computer operations but of social constructs like APIs) is immense. This is a long journey and a rewarding one. If you truly love this craft like I do, you'll be glad you took the time even if you never actually write an OS.

Now, the technical answer. You're going to need a bootloader, and that must be written in assembly language. After all, your processor doesn't know C#. Past the bootloader phase, you can write your OS code in any language you want and it'll run, assuming your language can compile to machine code binaries (and not bytecode!)

However, even in our current "glut of cycles" computing environment, an OS must be lean and efficient and that's nearly impossible to achieve in a higher level language, even more so in an interpreted language.

Chances are, you'll need to write your own compiler/interpreter of that given language as a core component of your OS. That core compiler would likely allow only a restricted subset of the language (and you'd bootstrap by writing a more robust compiler in the restricted sub-language). Otherwise the performance will be abysmal.

But all of this is horribly complex and a real discussion of the issues requires a depth of knowledge you probably currently lack. But if you have the drive to do so, you can easily change that, and then I'd happily debate approaches all day!

If it makes you feel any better, I do know enough to write an operating system, and still I sit around daydreaming, trying to figure out how much of an OS could I get away with writing in python. ;)

share|improve this answer
Technically there's little "answer" in there, but for me it's still the best one. –  Joachim Sauer Mar 9 '09 at 17:28
That's a fair comment but sometimes a person's question reveals that the information they need isn't the information they asked for. ;) –  Jason L Mar 11 '09 at 13:59
I don't want you to become jealous, but I was only 14 years old when I wrote my first "OS". It was written in only assembler as it was virtually impossible for me to get my compiler ( some very old version of visual studio ) to output executables not infected with any windows related crap. The OS was named GOSth ( Graphical OS, note the misspelling of Ghost ;D , English isn't my natural language ). It consisted of a Graphical shell ( 256 color GUI, Wohoo! ), Mousesupport, parts of the DOS-API implemented. Sadly enough my laptop doesn't have a floppy drive. And the sources is on a floppy... –  Frank Sep 11 '09 at 18:47
add comment

Yes. Use assembler. I would use Forth. Genera was an os made by symbolics** coded in Lisp. C is mostly used because it is trusted. We known how it works. And there exist c compilers for every cpu in the universe. Compilers for c are simple to build.

** Symbolics registered the first domain on the internet. (interesting fact)

share|improve this answer
I know the question shifted on you since your answer. So your answer isn't confusing to people reading this post-mortem: Originally the OP asked "can I write an operating system without using C/C++?" He later amended to "Can I write an operating system without using a low-level language?" –  Jason L Mar 11 '09 at 14:03
And to reply specifically to your comment, I've always had a soft-spot for Forth. If I ever actually have the free time to tackle throwing together an OS, I have a feeling I'd go with Forth as well. :) –  Jason L Mar 11 '09 at 14:04
Yepp, If I were the only one to use my os, then Forth would be the perfect tool. –  Flinkman Mar 12 '09 at 5:50
add comment

Sure. You could use pure assembler or choose a different high-level language.

But you usually don't want to. Because the amount of assembler code necessary in a modern operating system is rather low. Most code in an OS doesn't need at that low a level.

C gives a nice intermediate level of abstraction that still allows writing rather low-level code while not having to deal with all the details that assembler developers need to deal with.

Edit: once you remove assembly from the equation it becomes a lot more complicated. Setting up a decent operating system requires executing several machine code instructions that are simply not represented in high-level languages (because they are very, very machine-specific). You could theoretically produce pure machine code in a binary blob and jump to that location from a high-level language, but I consider that cheating, as you'd have to come up with that binary blob in the first place.

share|improve this answer
Shit, You won. It's nice for the rep to be on first row. –  Flinkman Mar 9 '09 at 17:00
There, get an upvote for your trouble ;-) –  Joachim Sauer Mar 9 '09 at 17:03
add comment

Yes, MenuetOS is an example of an operating system written using only assembler.

As you don't seem to be interested in assembler see also JNode, an operating system written in Java, and Singularity, an operating system written in C#.

share|improve this answer
Those poor soles. lol –  eduncan911 Mar 9 '09 at 17:02
(Your hyperlink is broken) –  teedyay Mar 9 '09 at 17:02
Thanks, Olafur. I didn't understand the link syntax to begin with. –  Daniel Watkins Mar 9 '09 at 17:16
add comment

There are numerous attempts to create hardware implementation of JVM. Of course OS for such hardware would be written in Java. See for example: http://www.jopdesign.com/

Also Nokia's S40 seems to be developed principally in Java.

share|improve this answer
add comment

Sure. C/C++ code is compiled into ASM code, but there are many other languages you could use in the same way.

You might not be able to use Java or C# since these rely on a Virtual Machine and that could be written in C.

Actually I believe there was a project to create an OS based on LISP, but it failed.

share|improve this answer
most compilers generate machine code, not assembler; also, it seems you've never heard of LISP machines: en.wikipedia.org/wiki/Lisp_machine –  Christoph Mar 9 '09 at 17:28
add comment

Sure. As long as there's a compiler available which can produce appropriate machine code, any language will do.

share|improve this answer
add comment

Check out http://common-lisp.net/project/movitz/. It's an OS entirely written in Lisp. I think it has it's own Assmebler, e.g. Lisp to machine code translator.

I love the idea of OS without C/C++ and especially a Lisp-based one.

share|improve this answer
Ever heard of the Symbolic Lisp Machine? –  Paul Tomblin Mar 9 '09 at 17:23
Sorry, "Symbolics". –  Paul Tomblin Mar 9 '09 at 17:24
not until now, thanks, sounds interesting –  siddhadev Mar 9 '09 at 17:49
It sounds weird you mention Movitz and admittedly never heard about Lisp machines. Lisp machines are considered the main source of inspiration for Movitz. Lisp machines were a commercial failure because they could not keep the pace with the "non-Lisp" competition, but with the tremendous raw hardware power we have today, why not trying again with an open source project? –  Halberdier Jul 26 '11 at 13:42
add comment

Yes. Obviously anything is possible in assembly but often not practical. There have been a few attempts at making operating systems in managed code (.NET, Java) with varying degrees of success.

share|improve this answer
add comment

you could write it in machine code? bu this is just binary. you could write it in assembly but this has a complex structure. you probably should write it in C because it translates directly to machine code when it is compiled, so it is faster than C#/C++ and simpler than assembly

share|improve this answer
add comment

If you really wanted to, then yes, you can write a whole operating system without using Assembly, C or C++, but I recon it would just be a waist of time. You could get a binary editor and program the whole language in Binary or Hexadecimal if you wanted to, it would take ages, but it's completely possible.

share|improve this answer
add comment

Your Answer


