如何机器间preT二进制? [英] How do machines interpret binary?

查看:239
本文介绍了如何机器间preT二进制?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我当时就在想,怎么做的机器间preTER二进制code?我所不解的是你的code获取的变成1和0使机器可以理解他们,但他们是如何做到这一点?难道仅仅是一个普通的文本到二进制翻译?

I was just thinking, how do machines interpreter binary code? All I understand is your code get's turned into 1 and 0's so the machine can understand them, but how do they do that? Is it just a normal text to binary translation?

推荐答案

首先,二进制并不意味着你认为这意味着(计算机上的任何数据,包括文本已经是二进制的,它只是我们决定方式显示和处理是不同的)。

First, "binary" doesn't mean what you think it means (any data on the computer, including text is already binary, it just the way we decide to display and handle is different).

二,编译不是一个简单的改造,奇怪的字符(如果是这样,我们就不需要针对不同的语言不同的编译器)。要真正有机器code有一定的了解,你要明白,它的目标架构。有很多种计算机体系结构,你的电脑就是其中之一。这是一个非常广泛的课题,需要计算机体系结构的坚实的理解把握。

Second, compilation is not a simple transformation to funny characters (if it were, we wouldn't need different compilers for different languages). To actually have some understanding of machine code, you need to understand the architecture that it targets. There are many computer architectures, your PC is just one of them. It is a very broad subject and needs firm understanding of computer architecture to grasp.

我将展示的MIPS指令的例子。如果你有兴趣,你可以阅读和获取有关问题的一些实际知识,尝试链接在帖子的末尾。

I will show an example of a MIPS instructions. If you are interested, you can read on and get some actual knowledge about the subject, try the links at the end of my post.

MIPS是一个流行的主题介绍,因为它的指令格式是更易消化的一个。 MIPS指令是32位宽。有3种指令在MIPS:R,I和J。我们来看看我的指令。

MIPS is a popular introductory subject because its instruction format is one of the more digestible ones. MIPS instructions are 32 bit wide. There are 3 kinds of instructions in MIPS: "R", "I" and "J". We will take a look at the "I" instructions.

当所述处理器获得的指令(32位数据)它读取它并决定如何处理它。 我的说明是这样的:

When the processor gets an instruction (32 bits of data) it reads it and decides what to do with it. "I" instructions look like this:

|------|-----|-----|----------------|
 opcode   rs    rt    immediate
   6      5     5     16               (the numbers show how wide are each part)

这些的意思是:


  • 运算code 告诉这是什么样的指令(例如:加法,减法,乘法和许多其他)。所有指令(包括R和J型)开始与6位运算code,这是处理器如何知道它是哪一种。

  • RS RT 是寄存器,是一种存储在可容纳32位值的处理器。 MIPS具有这些32并且它们通过它们的数量确定的。这是不一样的存储器,它是CPU本身的内部。

  • 立即是一个数字。这就是所谓,由于编号为在那里的指令,而不是在一个寄存器或存储器。

  • opcode tells what kind of instruction this is (for example: addition, subtraction, multiplication and many others). All instructions (including "R" and "J" types) start with the 6-bit opcode, and that's how the processor knows which kind it is.
  • rs and rt are registers, a kind of storage in the processor that can hold 32 bit values. MIPS has 32 of these and they are identified by their number. This is not the same as memory, it's inside the CPU itself.
  • immediate is a number. It is called that because the number is "right there" in the instruction, not in a register or memory.

加入一个具体的例子是的直接的存储在一个寄存器一个数字:

A concrete example of adding an immediate to a number stored in a register:

001000 00001 00010 0000000000000011

在这个例子中,我打破了指令分成几部分如上。该值的含义如下:

In this example, I broke the instruction into parts as above. The meaning of the values is the following:


  • 运算code 001000 办法阿迪或添加立即

  • RS 00001 1 十进制,因此指令,这部分告诉我们要使用的寄存器1为 RS

  • RD 00010 2 十进制,同样的想法与RS。

  • 立即 0000000000000011 3 十进制。

  • opcode: 001000 means addi or "add immediate".
  • rs: 00001 is 1 in decimal, so this part of the instruction tells the processor that we want to use register 1 as rs.
  • rd: 00010 is 2 in decimal, same idea as with rs.
  • immediate: 0000000000000011 is 3 in decimal.

阿迪指令是这样的:它需要在 RS 发现的价值,并增加了在立即价值它。之后,它会将结果为 RD 。所以,当指令完成后, RD 将包含3 + 2 = 5。

The addi instruction works like this: it takes the value found in rs and adds the immediate value to it. After that it puts the outcome into rd. So, when the instruction is done, rd will contain 3+2=5.

简而言之,编译器解析你的文字和生成的目标处理器,做你打算用你的程序做同样的事情的说明。正如你所看到的,还有就是我们的程序员写程序的文本再presentation之间的巨大差距,以及可运行机器code。

In a nutshell, compilers parse your text and generate instructions to the target processor that does the same thing that you intended to do with your program. As you can see, there is a huge gap between the textual representation of the program that us programmers write, and the runnable machine code.

在MIPS和计算机体系结构的一些有用的资源:

A few useful resources on MIPS and computer architecture:

  • Video lecture on computer architecture
  • How instruction decoding works inside a MIPS processor
  • Computer organization and design
  • MARS allows you to play with MIPS machine code

这篇关于如何机器间preT二进制?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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