硬件如何运行装配体?第一个汇编程序是如何编写的? [英] How does hardware run assembly? How was the first assembler written?

查看:91
本文介绍了硬件如何运行装配体?第一个汇编程序是如何编写的?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我自己上了一门关于编译器的课程,并制作了一个初级的基础知识,但我对第一个编译器仍然存有挥之不去的疑问.

Having taken a course on compilers and making a rudimentary one by myself, i still have this lingering doubt about the first compiler.

从高级别到低级别,我看到以C或C ++运行的代码被编译器转换为相应的汇编语言(例如gcc).这段代码是平台相关的(假设我使用的是Intel x86体系结构).

From a high to low level, i see code running in lets say C or C++ which gets converted to the respective assembly language equivalent by it's compiler (lets say gcc). This code is platform dependent (lets say i'm on intel x86 architecture).

现在出现了一个问题,硬件如何运行程序集?

Now comes the question, how does a hardware run assembly?

我记得在我的计算机组织类中,每个汇编语句都被转换为特定格式(取决于处理器),例如,诸如mov ax,bx之类的语句被转换为它的操作码,可以说0110 101010 101000.汇编器解析我的汇编语言程序中的每个语句并将其转换为机器代码,那么第一个汇编器是如何编写的?

I remember from my computer organization class that each and every assembly statement gets converted to a specific format (depending on the processor) for example, a statement like mov ax,bx gets converted to it's opcode let say 0110 101010 101000. Assuming the assembler parses every statement in my assembly language program and converts it into a machine code, then how was the first assembler written?

推荐答案

实际上,我认为您可以理解.首先是标题问题,硬件如何运行程序集.硬件以机器代码或机器指令或任何术语运行.正如您已经正确描述的那样,汇编语言是该机器代码的代表,但并不总是如此,而是接近一对一的关系,即一条asm指令与一条机器指令.这些都是位,一和零,硬件现在可以执行这些位描述的操作.

Actually I think you understand. First off the title question, how does hardware run assembly. Hardware runs on machine code or machine instructions or whatever term. As you have correctly described assembly is a representative of that machine code, and not always but is close to a one to one relationship one asm instruction to one machine instruction. These being bits, ones and zeros, the hardware can now perform the actions that the bits describe.

现在第一个汇编器是怎么写的?用铅笔和纸.通常,您可能会以某种伪汇编形式写下指令,因为您可能还没有完全定义语言,然后根据编码写下了位,汇编程序也会这样做.然后使用某种机制将这些位输入计算机,并告诉计算机运行.

Now how is the first assembler written? With pencil and paper. You typically write down the instruction in some sort of pseudo assembly as you may not have completely defined the language, and then you write down the bits based on the encoding, the same thing an assembler would do. Then using some mechanism you feed those bits into the computer and tell it to run.

最后,自然地,这对于大型程序来说变得很繁琐,因此您决定编写一个较大的程序来解析一种易于编写的语言,然后使用更复杂的语言和程序进行重复.

Eventually, naturally, this becomes tedious for larger programs so you decide to write a larger program that parses a language that is easier to write, then repeat that with more complicated languages and programs.

即使到了今天,也要取决于团队,他们的工作方式以及测试指令解码器等的个人工程师.仍然需要手工编写机器代码.最终,创建了汇编器,您切换到该汇编器,有时需要使用更高级别的编译器,并且大部分代码都切换到了该汇编器,但是在芯片开发领域,您仍然非常了解,并且会不时地修改该汇编器.机器代码级别的一条指令位.

Even today depending on the team and how they do things and the individual engineer testing the instruction decoder, etc. Writing machine code by hand still happens. Eventually the assembler is created and you switch to that and sometimes there is a higher level compiler and you switch to that for the bulk of the coding, but in the chip development world you still are very aware of and from time to time will modify the bits of an instruction at the machine code level.

这篇关于硬件如何运行装配体?第一个汇编程序是如何编写的?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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