Is it worth to write my system (small) in Assembly entirely?
Is it worth to write my system (small) in Assembly entirely?
Hi and I am new to OS Development and OSDev.org. Thank you for many documents and guide that help me to learn about OS Development.
I usually program in high-level languages like Pascal or Visual Basic but when come to OS Development, I prefer Assembly to high-level languages. Somehow, I find that write a small OS in Assembly if far more easy and simple than in C or Pascal (am I weird?)
Assembly has a weakness at maintainablity, so I keep my code well-structured (avoid spaghetti code as much as possible), using well-defined procedure interface to negate that weakness.
But recently, I have learned a sad truth that with modern superscalar, pipelined cpu, it is very difficult to average hand-optimised Assembly code to make it run as fast as good compiler-generated code. Therefore my Assembly code will run slower than most optimised compiler.
Should I continue to code my system in Assembly language?
I usually program in high-level languages like Pascal or Visual Basic but when come to OS Development, I prefer Assembly to high-level languages. Somehow, I find that write a small OS in Assembly if far more easy and simple than in C or Pascal (am I weird?)
Assembly has a weakness at maintainablity, so I keep my code well-structured (avoid spaghetti code as much as possible), using well-defined procedure interface to negate that weakness.
But recently, I have learned a sad truth that with modern superscalar, pipelined cpu, it is very difficult to average hand-optimised Assembly code to make it run as fast as good compiler-generated code. Therefore my Assembly code will run slower than most optimised compiler.
Should I continue to code my system in Assembly language?
Re: Is it worth to write my system (small) in Assembly entir
It's your OS, so do whatever you want to. Although how you can find assembler easier than C for anything but the most trivial programs is beyond me.
Bear in mind that assembler, unlike C, is locked to the processor you have chosen.
Bear in mind that assembler, unlike C, is locked to the processor you have chosen.
Re: Is it worth to write my system (small) in Assembly entir
Thanks, that's right, it is up to me to decided since no one care about a hobby os anyway.
About portability, I am fully aware of that drawback. So, before wrting the code, I design and write down the algorithm on the paper first and translate it to assembly code later. So even when I lost the code, I still have the design in paper and can reimplement it, even for another language (this method also reduces time for debugging considerably). Beside, buying an another machine with different architecture than Intel x86 is very hard for me.
About portability, I am fully aware of that drawback. So, before wrting the code, I design and write down the algorithm on the paper first and translate it to assembly code later. So even when I lost the code, I still have the design in paper and can reimplement it, even for another language (this method also reduces time for debugging considerably). Beside, buying an another machine with different architecture than Intel x86 is very hard for me.
Re: Is it worth to write my system (small) in Assembly entir
I don't know anything about your circumstances, but computers based on ARM processors are very common nowadays, and are cheaper than x86 computers. With emulaters such as qemu you don't even need other hardware to play with alternative processors.Congdm wrote:Beside, buying an another machine with different architecture than Intel x86 is very hard for me.
I wouldn't completely rule out the possibility of other architectures.
- Love4Boobies
- Member
- Posts: 2111
- Joined: Fri Mar 07, 2008 5:36 pm
- Location: Bucharest, Romania
Re: Is it worth to write my system (small) in Assembly entir
Note that maintainability and portability aren't the only issues. With a HLL, you have the option of asking the compiler to micro-optimize for a specific microarchitecture. With assembly, you have two choices:
- To not micro-optimize but instead write the code for your chosen architecture as generally as possible. (But then what is the point of using assembly?)
- To profile your code and provide micro-optimized routines for all the microarchitectures of your chosen architecture that you wish to support. (This means lots of duplicated code.)
"Computers in the future may weigh no more than 1.5 tons.", Popular Mechanics (1949)
[ Project UDI ]
[ Project UDI ]
Re: Is it worth to write my system (small) in Assembly entir
As an offtopic, my assembly code is usually quite unoptimized. I prefer the code being easy to read even it makes it slower. It executes extremely fast on modern hardware anyway. Of course, some critical parts are more optimized.Congdm wrote:it is very difficult to average hand-optimised Assembly code to make it run as fast as good compiler-generated code
My kernel is much slower and inefficient when compared to highly optimized ones (or "normal" ones). The kernel itself uses memory quite inefficiently because modern computers have it and when looking the system as a whole it does not matter. It goes without saying that the efficiency and elegancy are not mutually exclusive but I am not capable of getting both. I personally find my kernel being elegant which is the most important thing because it is, well, my kernel. Luckily, I work alone so I do not have to explain my ideas that may seem to be very unefficient (but have the rationale behind them). Well, the elegancy could also mean being highly efficient... well... maybe I stop talking. EOO (End of Offtopic).
No, you are not weird. Low-level things are easier when using an assembly language.Congdm wrote:Somehow, I find that write a small OS in Assembly if far more easy and simple than in C or Pascal (am I weird?)
Re: Is it worth to write my system (small) in Assembly entir
I knows that ARM architecture is popular nowadays but in developing countries (like my country), it isn't popular yet . I really want to programming in other architectures like ARM, Power, MIPS, Sparc, monstrous Itanium, or even old architectures like System/360, Motorola 68000.iansjack wrote:I don't know anything about your circumstances, but computers based on ARM processors are very common nowadays
Emulation may help but I didn't like it, I like the feeling of real machine
You are quite right, but I am not as lazy as you say, setting up build environment isn't that hard , but I don't like it.Love4Boobies wrote:I suspect that the reason why you find it easier to write it in assembly rather than C or some other HLL is that you don't know how to set up a proper build environment and are too lazy to research it
I agree with you too, I focus on clear design, choosing good algorithms, using abstraction to make problem easier and managable. Maybe if I choose Assembly, my code won't run fast, but if it is clear and managable, what is the problem? It can't compare with big OS anyway. In my system, there isn't kernel, everything is module and can be replaceable. It can run only with basic Interrupt, Video, Keyboard module and a basic module loader, nothing else.Antti wrote:As an offtopic, my assembly code is usually quite unoptimized. I prefer the code being easy to read even it makes it slower. It executes extremely fast on modern hardware anyway. Of course, some critical parts are more optimized.My kernel is much slower and inefficient when compared to highly optimized ones (or "normal" ones). The kernel itself uses memory quite inefficiently because modern computers have it and when looking the system as a whole it does not matter.
- Love4Boobies
- Member
- Posts: 2111
- Joined: Fri Mar 07, 2008 5:36 pm
- Location: Bucharest, Romania
Re: Is it worth to write my system (small) in Assembly entir
You seem to be okay with making a big mistake before even starting. What chance does your project stand then?Congdm wrote:You are quite right, but I am not as lazy as you say, setting up build environment isn't that hard , but I don't like it.Love4Boobies wrote:I suspect that the reason why you find it easier to write it in assembly rather than C or some other HLL is that you don't know how to set up a proper build environment and are too lazy to research it
You are probably under the impression that it doesn't really matter, that the project is the actual code, that from now on you will make good choices, that in fact it will be manageable, etc. These problems are extremely common with inexperienced people. I used to think these things myself. Fortunately, books have been written for those who wish to avoid these mistakes.
"Computers in the future may weigh no more than 1.5 tons.", Popular Mechanics (1949)
[ Project UDI ]
[ Project UDI ]
Re: Is it worth to write my system (small) in Assembly entir
I agree that using just the assembly is not a good idea in a long run. Meanwhile, I would say that it does not matter as far as the first operating system related project is concerned. It may actually be a good idea to use just the assembly there.Love4Boobies wrote:You seem to be okay with making a big mistake before even starting.
After gaining some experience, you can start your project from scratch. With a proper build environment.
Re: Is it worth to write my system (small) in Assembly entir
I am just joking about that lazy part. Of course I can not stick with Assembly forever, even if I can, almost all sane people don't like coding in Assembly, so if I choose only Assembly, most people will never involve with my project. (A bit off-topic: my question is with small project, is using all assembly languages practical, not with big project)Love4Boobies wrote:You seem to be okay with making a big mistake before even starting. What chance does your project stand then?
Unprove_ranting:
Instead, I designed my system with structured modules and clear interfaces, forbiding cross-dependence so modules can be replaceable individually. Anyone can use any languages to write/change a module with requirements: conform to the binary interface and design in a structured way. With that design, when I code in high-level languages, I can still reuse my old Assembly codebase easily without any problem. That is Replaceable part.
The main reason that I design my project in that way is: There is no perfect design, and never will. We can make it better by changing it but can not make it perfect. So no design is static, it always evolve to something better. The only stable thing is changing, therefore I design it with ability to change but can inherit its ancestor when need.
End_ranting
Re: Is it worth to write my system (small) in Assembly entir
I think this is a pretty good reasoning. I find it very important to keep in your head that nothing is perfect. To answer your "Is it worth to write my system (small) in Assembly entirely?" question:Congdm wrote: The main reason that I design my project in that way is: There is no perfect design, and never will. We can make it better by changing it but can not make it perfect. So no design is static, it always evolve to something better. The only stable thing is changing, therefore I design it with ability to change but can inherit its ancestor when need.
I say use C, like most do. And they do for a reason. It's portable AND fast. Even if it ends up not as fast as assembly, I think it is the language with the best speed/portability and low/high level of abstraction ratio. I somewhere read that ISA's should be made for compilers, not for people. I think that is very true.
- Griwes
- Member
- Posts: 374
- Joined: Sat Jul 30, 2011 10:07 am
- Libera.chat IRC: Griwes
- Location: Wrocław/Racibórz, Poland
- Contact:
Re: Is it worth to write my system (small) in Assembly entir
That "C is not as fast as assembly" statement is getting obsolete, as modern (and even not-so-modern) compilers are mainly optimizers...
Reaver Project :: Repository :: Ohloh project page
<klange> This is a horror story about what happens when you need a hammer and all you have is the skulls of the damned.
<drake1> as long as the lock is read and modified by atomic operations
<klange> This is a horror story about what happens when you need a hammer and all you have is the skulls of the damned.
<drake1> as long as the lock is read and modified by atomic operations
Re: Is it worth to write my system (small) in Assembly entir
And in most cases highly optimized asm code is unreadable, so when you use pure asm you have trade-off between speed and ability for other people to study and support your code.
- Love4Boobies
- Member
- Posts: 2111
- Joined: Fri Mar 07, 2008 5:36 pm
- Location: Bucharest, Romania
Re: Is it worth to write my system (small) in Assembly entir
I've heard this argument before but it doesn't really make sense to me. Here's how I read it: He's learning and should thus be encouraged to do wrong things. The whole point of learning is to find out how to avoid the wrong things.Antti wrote:I agree that using just the assembly is not a good idea in a long run. Meanwhile, I would say that it does not matter as far as the first operating system related project is concerned. It may actually be a good idea to use just the assembly there.Love4Boobies wrote:You seem to be okay with making a big mistake before even starting.
After gaining some experience, you can start your project from scratch. With a proper build environment.
"Computers in the future may weigh no more than 1.5 tons.", Popular Mechanics (1949)
[ Project UDI ]
[ Project UDI ]
Re: Is it worth to write my system (small) in Assembly entir
From all responses, I concluded that writing in Assembly entirely is a bad idea. But for now, I decided to continue with Assembly. I consider that as a challenge to test my designing and programming skills. Thanks for response.
Also:
Also:
In my opinion, the main purpose of learning is to correct wrong things.Nable wrote:The whole point of learning is to find out how to avoid the wrong things.