实际的机器代码在各个方面是什么样的? [英] What does actual machine code look like at various points?

查看:131
本文介绍了实际的机器代码在各个方面是什么样的?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

对于实际的机器代码似乎有很多意见.我听说有人说它是汇编语言,二进制或十六进制.

There seems to be many opinions on what machine code actually is. I've heard some say it's assembly, or binary, or hex.

说机器代码本质上是针对特定处理器的一组指令是否正确?如果是这样,我想这些可以用二进制或十六进制表示法或汇编形式表示.但是,未经翻译的实际"机器代码是什么样的呢?它基于体系结构的字长吗?还是所有意图和目的的十六进制都是默认表示形式?

Is it correct to say that machine code is essentially a set of instructions for a particular processor? If so, I imagine these can be represented in binary or hexadecimal notation, or assembly. But what does the non-translated "actual" machine code look like? Is it based on the word size of the architecture? Or is hexadecimal for all intents and purposes the default representation?

坐在硬盘上看起来像什么?坐在收银机上看起来像什么?在处理时怎么样,那时候仅仅是一组电压变化吗?

What does it look like when sitting on a hard drive? What does it look like when sitting in a register? How about when it's being processed, is it simply a set of voltage changes at that point?

推荐答案

机器代码是简单的二进制数据,与特定处理器体系结构的CPU指令相对应.

Machine code is simply binary data that corresponds to CPU instructions for a specific processor architecture.

我不会过多地存储它,因为这取决于它的存储位置.例如,在磁盘上,通常将其存储为一系列磁化区域.在存储方面,机器代码与其他二进制数据没有什么不同.如果您的问题更多地是关于如何在计算机上存储数据,则应该研究计算机中的各种数据存储设备,例如HDD,RAM和寄存器,等等.

I won't go into how it is stored too much, because that depends on where it is stored. On disk, for example, it is generally stored as a sequence of magnetized regions. Machine code is no different from other binary data in the storage aspect. If your question is more about how data is stored on a computer, you should research the various data-storage devices in a computer, like HDD, RAM, and registers, to name a few.

可视化机器代码存储方式的最简单方法是在十六进制编辑器中查看.这显示了由十六进制数字表示的二进制数据.例如,按照以下说明进行操作:

The easiest way to visualize how machine code is stored is to look at some in a hex editor. This shows you the binary data represented by hex numbers. For example, take the instruction:

0xEB 0xFE

可以很容易地将其编写为1110101111111110或60414.这取决于您如何将二进制转换为人类可读的形式.

This could easily be written 1110101111111110, or 60414. It depends how you want to convert binary into human-readable form.

此指令表示无限循环. (这是假设它正在x86 CPU上运行.其他CPU可以根据需要对其进行解释.)可以将其编码为如下代码:

This instruction represents an infinite loop. (This is assuming it is being run on an x86 CPU. Other CPU's could interpret it however they want.) It can be coded in assembly like this:

j:
jmp j

运行汇编程序时,它将使用上面的代码并将其转换为上面的二进制机器代码.

When you run the assembler, it takes the above code and turns it into the binary machine code above.

说明实际上是两个部分.第一个是称为操作码的0xEB.当此代码进入CPU时,它意味着:从程序中读取一个字节,然后跳过那么多字节的数据.然后,CPU读取字节0xFE.由于期望有符号整数,因此它将二进制数据解释为数字-2.然后完成读取指令,并且指令指针向前移动2个字节.然后执行指令,使指令指针向前移动-2(0xFE)字节,从而有效地将指令指针设置为与指令启动时相同的值.

The instruction is really two parts. The first is what is known as the opcode, and is the 0xEB. When this code goes into the CPU, it means: Read a byte from the program, and skip that many bytes of data. Then the CPU reads the byte 0xFE. Since it expects a signed integer, it interprets the binary data as the number -2. The instruction is then done being read, and the instruction pointer moves forward 2 bytes. The instruction is then executed, causing the instruction pointer to move forward -2 (0xFE) bytes, which effectively sets the instruction pointer to the same value as it had when the instruction was started.

我希望这能回答您的问题.如果您想了解CPU的内部工作原理,请阅读微码和电子逻辑门.基本上,这是一堆电压差,例如1位是5伏电荷,0位是0位电荷.

I hope this answers your question. If you are wondering about the internal workings of CPU's, read up on microcode and electronic logic gates. Basically, it's a bunch of voltage differences, such as a 1 bit being a 5 volt charge and a 0 bit being a 0 bit charge.

这篇关于实际的机器代码在各个方面是什么样的?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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