是否严格要求组装以制造“最低"的?操作系统的一部分? [英] Is assembly strictly required to make the "lowest" part of an operating system?

查看:19
本文介绍了是否严格要求组装以制造“最低"的?操作系统的一部分?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是一名中级(抽象)程序员,几个月前我开始考虑是否应该减少或增加抽象(我选择减少).

Im a mid-level(abstraction) programmer, and some months ago i started to think if i should reduce or increase abstraction(i've chosen to reduce).

现在,我认为我已经完成了大部分关于我需要什么的研究",但仍有一些问题.

Now, i think i've done most of the "research" about what i need, but still are a few questions remaining.

现在我实际上什么都不做",我只是加强我的 C 技能(买了K&RC Programing Lang"),我想(在感觉舒服之后)开始学习操作系统(比如 minix)只是为了学习目的,但我有一个想法卡在我的脑海里,我真的不知道我是否应该在意.

Right now while im "doing effectively nothing", im just reinforcing my C skills (bought "K&R C Programing Lang"), and im thinking to (after feel comfortable) start studying operating systems(like minix) just for learning purposes, but i have an idea stuck in my mind, and i don't really know if i should care.

理论上(我认为,不确定),高级语言不能直接引用硬件(如寄存器、内存位置等),因此基础的完美语言"将是汇编.

In theory(i think, not sure), the higher level languages cannot refer to the hardware directly (like registers, memory locations, etc...) so the "perfect language" for the base would be assembly.

我已经研究过汇编(前段时间)只是为了看看它是怎么回事(由于本书使用过时的调试器(Assembly Language Step By Step,适用于 Linux!),我停在了书的中间)但是根据我的阅读,我不太喜欢这种语言.

I already studied assembly(some time ago) just to see how it was (and i stopped in the middle of the book due to the outdated debugger that the book used(Assembly Language Step By Step, for Linux!)) but from what i have read, i din't liked the language a lot.

所以问题很简单:操作系统(引导加载程序/内核)是否可以在不涉及一行汇编的情况下进行编程,并且仍然有效?

So the question is simple: Can an operating system(bootloader/kernel) be programmed without touching in a single line of assembly, and still be effective?

即使可以,也不会是跨架构"吧?(i386/arm/mips 等...)

Even if it can, it will not be "cross-architecture", will it? (i386/arm/mips etc...)

感谢您的支持

推荐答案

您可以在不组装的情况下完成大量工作.Linux 或 NetBSD 不必为它运行的众多目标中的每一个都完全重写或修补.大多数代码是可移植的,然后有抽象层,在抽象层之下,您可以找到目标特定层.即使在目标特定层内,大多数代码也不是 asm.我想打消这个错误的想法,即为了为设备驱动程序编写寄存器或内存,例如您需要 asm,您不要将 asm 用于此类事情.您将 asm 用于 1) 处理器具有的指令,您无法使用高级语言生成这些指令.或 2) 高级语言生成的代码太慢.例如,在 ARM 中启用或禁用中断有一条特定的指令用于访问您必须使用的处理器状态寄存器,因此需要 asm.但是中断控制器的编程都是用高级语言完成的.第二点的一个例子是你经常在 C 库中发现 memcpy 和其他类似的大量使用的库函数是手工编码的 asm,因为它的速度要快得多.

You can do a significant amount of the work without assembly. Linux or NetBSD doesnt have to be completely re-written or patched for each of the many targets it runs on. Most of the code is portable and then there are abstraction layers and below the abstraction layer you find a target specific layer. Even within the target specific layers most of the code is not asm. I want to dispell this mistaken idea that in order to program 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 a processor has that you cannot produce using a high level language. or 2) where high level language generated code is too slow. For example in the ARM to enable or disable interrupts there is a specific instruction for accessing the processor state registers that you must use, so asm is required. but programming the interrupt controller is all done in the high level language. An example of the second point is you often find in C libraries that memcpy and other similar heavily used library functions are hand coded asm because it is dramatically faster.

虽然您当然可以在 ASM 中编写和执行任何您想做的事情,但您通常会发现高级语言用于直接访问硬件(如寄存器、内存位置等)".您应该继续强化您的 C 技能,不仅要使用 K&R 书籍,还要浏览各种 C 标准,您可能会发现有多少实现定义"项目(例如位域)令人不安,如何提升可变大小等等.仅仅因为您在 10 年前编写的程序一直在使用一个/一个特定品牌的编译器(msvc、gcc 等)进行编译和工作,并不意味着代码是干净的、可移植的并且将继续工作.不幸的是,gcc 已经教会了许多非常糟糕的编程习惯,当用户在十年左右的时间里发现自己不了解该语言并不得不重做他们如何使用该语言解决问题时,这些习惯会让用户感到震惊.

Although you certainly CAN write and do anything you want in ASM, but you typically find that a high level language is used to access the "hardware directly (like registers, memory locations, etc...)". You should continue to re-inforce your C skills not just with the K&R book but also wander through the various C standards, you might find it disturbing how many "implementation defined" items there are, like bitfields, how variable sizes are promoted, etc. Just because a program you wrote 10 years ago keeps compiling and working using a/one specific brand of compiler (msvc, gcc, etc) doesnt mean the code is clean and portable and will keep working. Unfortunately gcc has taught many very bad programming habits that shock the user when the find out they didnt know the language a decade or so down the road and have to redo how they solve problems using that language.

这篇关于是否严格要求组装以制造“最低"的?操作系统的一部分?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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