How does a computer distinguish between Data and Instructions?

与世无争的帅哥 提交于 2019-12-01 09:45:01

You are on the verge of an important realization: data has no meaning without metadata - in order to make sense of a given sequence of bits, there has to be some "knowledge" about how those bits are supposed to be interpreted.

As far as instructions are concerned, the CPU's instruction set defines the size of each instruction and its accompanying data. Each instruction begins with the opcode, and the following data is typically fixed size (and the size depends on the opcode). Each instruction is executed in order (until a jump instruction is encountered), starting from some initial address that is hardwired into the CPU.

So if the initial address happens to be the address of the MAIN label, the first opcode the CPU sees will be 0000 0001, and so it will know that it is an LDA instruction, which it knows is supposed to be followed by a four bit number. Whatever follows those four bits is the next instruction.

What happens if a bad jump instruction is executed later, sending the CPU to the third bit group in your example? (Based on your example, I'm guessing that the CPU operates with four-bit "bytes".) Then indeed, the CPU will mistake 0100 0001 for an opcode and some number of the following bits as the data for that opcode, and things will likely go very wrong.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!