处理器/寄存器/存储器中的数据,地址和指令有何区别? [英] How is data, address and Instruction differentiated in Processor/Register/memory?

查看:288
本文介绍了处理器/寄存器/存储器中的数据,地址和指令有何区别?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在处理器中,如何区分数据,地址和指令?在执行程序时,当所有内容都在0 s and 1 s并且寄存器的数据和地址都装入时,处理器如何区分指令?

In Processor, how are Data, Address and instructions are differentiated? When a program is executed, how is processor differentiate instructions when everything is in 0s and 1s and register`s load both data, addresses?

推荐答案

处理器仅执行您要执行的操作.如您所述,处理器无法分辨内存中数据"和代码"之间的区别:它们全都是字节序列.您就是要告诉它与定义该字节如何处理的那些字节有关.

The processor only does what you tell it to do. As you noted, the processor can't tell the difference between "data" and "code" in memory: it's all just a sequence of bytes. It's what you tell it to do with those bytes that defines how it's treated.

编译程序时,生成的可执行文件中包含信息,该信息说明哪些部分是代码,哪些部分是数据.执行程序时,操作系统将代码和数据加载到内存的不同部分,然后告诉处理器在程序的入口点开始执行代码.处理器从那里获取第一条指令,执行该指令,然后继续执行下一条指令.

When a program is compiled, the generated executable file has information in it that says which parts are code and which parts are data. When a program is executed, the operating system loads code and data into different parts of memory and then tells the processor to start executing code at the program's entry point. From there, the processor fetches the first instruction, executes it, and moves on to the next instruction.

这当然很简单,但是我想你明白了.

That's all very simplified, of course, but I think you get the idea.

在较旧的处理器和较旧的操作系统中,没有什么可以阻止您告诉处理器开始执行数据段中间的指令.或者,实际上,通过修改代码段中间的数据",从而可以进行自我修改的代码.较新的处理器和操作系统通常具有某种形式的数据执行保护和锁定功能,以防止修改代码.否则,自修改代码可能会带来巨大的安全风险.

In older processors and older operating systems, nothing stops you from telling the processor to start executing instructions that are in the middle of a data segment. Or, in fact, from modifying "data" in the middle of a code segment--thereby making self-modifying code. Newer processors and operating systems usually have some form of data execution prevention and locks to prevent modification of code. Otherwise, self-modifying code can become a huge security risk.

简短的答案:处理器将代码视为代码,因为您告诉了它.否则,一切都只是内存中的字节.

The short answer: the processor treats code as code because you tell it to. Otherwise, everything's just bytes in memory.

这篇关于处理器/寄存器/存储器中的数据,地址和指令有何区别?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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