是否可以在不使用一行C/C ++代码的情况下编写整个操作系统? [英] Can a whole operating system be written without using even one line of C/C++ code?

查看:85
本文介绍了是否可以在不使用一行C/C ++代码的情况下编写整个操作系统?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

即使不使用一行C/C ++代码也可以编写整个操作系统吗?

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

要添加到列表中的另一个-程序集

One more to add to the list - assembly

推荐答案

是,不是.

首先,重要的是要记住,无论您选择哪种语言,最终编译后的产品都是汇编语言(或更准确地说是机器代码).甚至解释器(例如cpython解释器)最终也将您的脚本翻译成机器代码.

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.

首先,个人方面:如果还不知道如何使用汇编语言和C来编写操作系统,那么尝试OS设计绝对没事.

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.

那些刚接触编程的人通常会遇到这样的问题,因为他们想要做与编写新OS一样酷的事情,而无需进行任何必要的学习来尝试这样的项目.他们想知道高级语言是否可以绕过所有凌乱的学习.

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.

这并不排除遵循最终的OS设计之路!如果这是您的热情,那么请从顶部开始,然后逐步降低.获取有关网络协议,内存管理,线程等的书籍,解决每个主要子系统的问题,并熟悉它.如果不能使用旧的,就不能写新的!

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.

请记住,必需的知识量(不仅是计算机操作的知识,还包括API之类的社会结构)的知识是巨大的.这是一段漫长而又有意义的旅程.如果您像我一样真正喜欢这项技术,那么即使您从未真正编写过操作系统,也很高兴您花了一些时间.

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.

现在是技术答案.您将需要一个引导程序,并且该引导程序必须用汇编语言编写.毕竟,您的处理器不知道C#.在引导加载程序阶段结束之后,您可以使用所需的任何语言编写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.

可能是,您需要编写自己的给定语言的编译器/解释器作为OS的核心组件.该核心编译器可能仅允许语言的受限子集(您可以通过在受限子语言中编写功能更强大的编译器进行引导).否则性能将很糟糕.

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!

如果能让您感觉更好,我确实知道足以编写一个操作系统,但我仍然白日做梦,试图弄清楚我可以用python编写获得多少操作系统. ;)

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. ;)

这篇关于是否可以在不使用一行C/C ++代码的情况下编写整个操作系统?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆