Writing Os entirely in assembly

Question about which tools to use, bugs, the best way to implement a function, etc should go here. Don't forget to see if your question is answered in the wiki first! When in doubt post here.
Post Reply
SayedMohsen64
Posts: 16
Joined: Mon Jan 26, 2015 2:56 am

Writing Os entirely in assembly

Post by SayedMohsen64 »

Like title says, has anyone here done this? What are your feedback?
User avatar
BrightLight
Member
Member
Posts: 901
Joined: Sat Dec 27, 2014 9:11 am
Location: Maadi, Cairo, Egypt
Contact:

Re: Writing Os entirely in assembly

Post by BrightLight »

I write my OS entirely in assembly, and I think it is great.
I don't know other languages well, TBH. But I'm not even willing to learn C/C++; I'm very comfortable with assembly.
Pros:
- Smaller size files.
- (Probably) faster execution.
- More control over what goes on behind the scenes.

Cons:
- Not portable.
- Gets cluttered and unreadable with time.
You know your OS is advanced when you stop using the Intel programming guide as a reference.
User avatar
Muazzam
Member
Member
Posts: 543
Joined: Mon Jun 16, 2014 5:59 am
Location: Shahpur, Layyah, Pakistan

Re: Writing Os entirely in assembly

Post by Muazzam »

I did and do write; though, the OS is not quite public yet. Well, it's just a tiny OS and lacks very basic features (yet), but it has a text-editor, FASM port, and 2048-like game--everything in an assembly language. Just drop me a PM, if you're interested.

(I'm not advertising anything here; the whole project is free and in public domain.)

Just as Omar, Assembly is the only language that I know good. Disadvantages are (1) Assembly is complex, though not hard (2) "real" OSDev'ers would hate you.
Last edited by Muazzam on Fri Aug 28, 2015 2:32 am, edited 1 time in total.
onlyonemac
Member
Member
Posts: 1146
Joined: Sat Mar 01, 2014 2:59 pm

Re: Writing Os entirely in assembly

Post by onlyonemac »

I write in assembly because I want to control exactly what instructions the CPU is executing. I want to be able to say that the CPU is running only what I have written, not some compiler's interpretation of what I have written.
When you start writing an OS you do the minimum possible to get the x86 processor in a usable state, then you try to get as far away from it as possible.

Syntax checkup:
Wrong: OS's, IRQ's, zero'ing
Right: OSes, IRQs, zeroing
User avatar
iansjack
Member
Member
Posts: 4706
Joined: Sat Mar 31, 2012 3:07 am
Location: Chichester, UK

Re: Writing Os entirely in assembly

Post by iansjack »

I believe that trying to write an OS entirely in assembly is a classic beginner's mistake which most (eventually) grow out of. The advantages of using a high-level language are overwhelming; the advantages of assembly are overrated (and mostly wrong).

But don't worry - even some of the pioneers made this mistake (until they had written a suitable language).
User avatar
Roman
Member
Member
Posts: 568
Joined: Thu Mar 27, 2014 3:57 am
Location: Moscow, Russia
Contact:

Re: Writing Os entirely in assembly

Post by Roman »

onlyonemac wrote:not some compiler's interpretation of what I have written.
You sound like someone speaking language X not good enough and blaming someone speaking that language natively for not properly understanding you.
"If you don't fail at least 90 percent of the time, you're not aiming high enough."
- Alan Kay
User avatar
Combuster
Member
Member
Posts: 9301
Joined: Wed Oct 18, 2006 3:45 am
Libera.chat IRC: [com]buster
Location: On the balcony, where I can actually keep 1½m distance
Contact:

Re: Writing Os entirely in assembly

Post by Combuster »

Maybe because of all flavours of braces failing on braille displays?
"Certainly avoid yourself. He is a newbie and might not realize it. You'll hate his code deeply a few years down the road." - Sortie
[ My OS ] [ VDisk/SFS ]
User avatar
iansjack
Member
Member
Posts: 4706
Joined: Sat Mar 31, 2012 3:07 am
Location: Chichester, UK

Re: Writing Os entirely in assembly

Post by iansjack »

I think I'll write an operating system entirely in microcode. That way I'll be sure that the processor is doing exactly what I want it to.
User avatar
SpyderTL
Member
Member
Posts: 1074
Joined: Sun Sep 19, 2010 10:05 pm

Re: Writing Os entirely in assembly

Post by SpyderTL »

iansjack wrote:I think I'll write an operating system entirely in microcode. That way I'll be sure that the processor is doing exactly what I want it to.
I actually considered this, until I learned that Intel doesn't allow you to update their microcode. :)

But if it weren't for that, I probably would have tried it. 8)
Project: OZone
Source: GitHub
Current Task: LIB/OBJ file support
"The more they overthink the plumbing, the easier it is to stop up the drain." - Montgomery Scott
onlyonemac
Member
Member
Posts: 1146
Joined: Sat Mar 01, 2014 2:59 pm

Re: Writing Os entirely in assembly

Post by onlyonemac »

Combuster wrote:Maybe because of all flavours of braces failing on braille displays?
Actually I don't have a braille display. But while C code is a pain to listen to with a screenreader, assembler is even more painful. Opcode mnemonics get slurred into their operands and unless you kind of know what you're expecting to hear you're going to be spending a lot of time pressing the arrow keys to read each line character-by-character. And you can show a brace character on a braille display but it's not easy to read, no, because it involves multiple braille characters in a row. But then, listening to C code without headphones generally just leads to my mother saying "why does it keep saying 'rat race'?" when she mis-hears "right brace" as "rat race" and refuses to shut up when I tell her to! :-D
SpyderTL wrote:I actually considered this, until I learned that Intel doesn't allow you to update their microcode. :)

But if it weren't for that, I probably would have tried it. 8)
I assume you would have acquired an adequate stockpile of CPUs, as it is rather easy to brick them by damaging the microcode. ;-)
When you start writing an OS you do the minimum possible to get the x86 processor in a usable state, then you try to get as far away from it as possible.

Syntax checkup:
Wrong: OS's, IRQ's, zero'ing
Right: OSes, IRQs, zeroing
Kevin
Member
Member
Posts: 1071
Joined: Sun Feb 01, 2009 6:11 am
Location: Germany
Contact:

Re: Writing Os entirely in assembly

Post by Kevin »

onlyonemac wrote:I assume you would have acquired an adequate stockpile of CPUs, as it is rather easy to brick them by damaging the microcode. ;-)
Are you sure? I don't think microcode updates are persistent, so shouldn't a simple power cycle fix things?
Developer of tyndur - community OS of Lowlevel (German)
Ready4Dis
Member
Member
Posts: 571
Joined: Sat Nov 18, 2006 9:11 am

Re: Writing Os entirely in assembly

Post by Ready4Dis »

I wrote a smallish OS in assembly before moving on.
http://ready4dis.8m.com/cgi-bin/i/PhatO ... 271105.JPG

32-bit, preemptive multitasking, virtual memory manager, keyboard, mouse, hdd, fdd, file system (fat), supported VESA (VBE). It wasn't to bad to write, came out to like 12kb total. With the font set and graphics it was a whopping 24kb. The GUI was written in C, the OS written in assembly. While it was a great learning experience, which is the reason I did it in the first place, I re-wrote it in C as I originally planned. I don't have any benchmarks, but I doubt the asm version is any faster in reality, and the fact that it's much easier (for me) to implement more advanced algorithms in C, the C version probably ended up faster in general due to a better design, and it's much easier to extend or use on other hardware. Of course, the C version ended up being much larger, but it also ended up with many more features (virtual file system, vs individual file systems, a better task scheduler, a command line as well as GUI, SMP, and 64-bit is working, but not done...). Could I write it all in asm, yes. Do I want to? No, it'll take a lot longer for little benefit in my opinion.
onlyonemac
Member
Member
Posts: 1146
Joined: Sat Mar 01, 2014 2:59 pm

Re: Writing Os entirely in assembly

Post by onlyonemac »

Kevin wrote:
onlyonemac wrote:I assume you would have acquired an adequate stockpile of CPUs, as it is rather easy to brick them by damaging the microcode. ;-)
Are you sure? I don't think microcode updates are persistent, so shouldn't a simple power cycle fix things?
Normally an "update" system is designed such that the device retains the latest version.
When you start writing an OS you do the minimum possible to get the x86 processor in a usable state, then you try to get as far away from it as possible.

Syntax checkup:
Wrong: OS's, IRQ's, zero'ing
Right: OSes, IRQs, zeroing
onlyonemac
Member
Member
Posts: 1146
Joined: Sat Mar 01, 2014 2:59 pm

Re: Writing Os entirely in assembly

Post by onlyonemac »

Actually I've just researched it some more and the updates are not persistant.

However it is certainly possible to update the microcode on an Intel CPU.
When you start writing an OS you do the minimum possible to get the x86 processor in a usable state, then you try to get as far away from it as possible.

Syntax checkup:
Wrong: OS's, IRQ's, zero'ing
Right: OSes, IRQs, zeroing
Post Reply