Is assembly strictly required for the "lowest" part of the operating system?

I am a middle-level programmer (abstraction), and a few months ago I began to think whether abstraction should be reduced or increased (I decided to reduce).

Now, I think I did most of the “research” about what I need, but there are still a few questions left.

Right now, when I am “doing nothing efficiently”, I am simply enhancing my C skills (I bought “K & RC Programming Lang”) and they need to (after feeling comfortable) start learning operating systems (for example, minix) just for training but I have an idea stuck in my head and I really don't know if I should take care.

In theory (I think I'm not sure), higher-level languages ​​cannot directly refer to hardware (for example, registers, memory cells, etc.), so the "ideal language" for the database will be an assembly.

I already studied the assembly (some time ago) to see how it was (and I stopped in the middle of the book because of the outdated debugger that the book used (the assembly language Step By Step, for Linux!)), But because I read, I do not really like the language.

So, the question is simple: is it possible to program the operating system (bootloader / kernel) without touching one assembly line and still be efficient?

Even if it is possible, it will not be cross-architecture, right? (i386 / arm / mips, etc.)

thanks for the support

+4
source share
3 answers

You can do significant work without assembly. Linux or NetBSD does not have to be completely rewritten or patched for each of the many purposes it works for. Most of the code is portable, and then there are levels of abstraction and below the level of abstraction you find the target layer. Even in target specific layers, most of the code is not asm. I want to talk about this erroneous idea that for programming registers or memory for a device driver, for example, that you need asm, you do not use asm for such things. You use asm for 1) instructions that the processor has that you cannot produce using a high-level language. or 2) where high-language code is generated too slowly. For example, in ARM, to enable or disable interrupts, there is a specific command for accessing the processor status registers that you must use, so asm is required. but interrupt controller programming is done in a high-level language. An example of the second point is that you often find in C libraries that memcpy and other similar highly used library functions are manually managed by asm because it happens much faster.

Although you certainly CAN write and do whatever you want in ASM, you will usually find that a high-level language is used to access "hardware directly (for example, registers, memory locations, etc.)." You should continue to re-inform your C skills not only with the K & R book, but also wander around the various C standards, you may find it worries how many elements are defined in the “implementation”, like bit fields, how variable sizes and etc. Just because the program you wrote 10 years ago continues to compile and work using one specific brand of compiler (msvc, gcc, etc.) does not mean that the code is clean and portable, and will continue to work. Unfortunately, gcc taught many very bad programming habits that shock the user when they find out that they haven’t known the language for a decade or so in the future and must repeat how they solve problems using this language.

+3
source

You yourself answered your question: "higher-level languages ​​cannot directly refer to equipment."

If you want it or not, at some point you will have to deal with assembly / machine code if you want to create an OS.

Interrupt and exception handlers must have some assembly code in them. Therefore, you need a scheduler (if not directly, indirectly). And the system call mechanism. And the bootloader.

+2
source

What I learned in past reading websites and books is that: a) many programmers do not like assembly language because of the reasons we all know. b) the main programming language for the OS, apparently, is C and even C ++ c) assembly language can be used to "speed up the code" after profiling the source code in C or C ++ (the language does not matter)

Thus, the combination of a middle-level language and a low-level language is inevitable in some cases. For example, there is no need to speed up code execution to wait for user input. If you need to build the shortest and fastest code for one specific range of computers (AMD, INTEL, ARM, DIGITAL-ALPHA, ...), then you should use assembler. My opinion...

0
source

All Articles