Assembler mov issue

久未见 提交于 2019-12-02 04:06:39

You can't, because the instruction set doesn't contain an instruction to do that. It is just one of the many idiosyncrasies of the x86.

These kind of restrictions are fairly normal for assembly languages. Most architectures contain some registers that are treated specially (for example the processor status word), though usually fewer than the x86 architecture.

The reason to not provide an instruction for all possible moves is to reduce the size of the instruction set, so that an instruction takes less memory. Overall it is more efficient to do moves that are rarely needed in two steps.

General purpose register as the 'ax' is designed to hold the 16 bit number pointing to the data (in your case the string inside the DATA)

So if you try to directly pass the data to the special register (ds or data segment here) it will not work correctly as it does not know to accept data that way. So we first get that 'number' or the point in memory location where data starts & pass that point to ds register.

I'm no expert but this is how I understand this constraint to work.

The Segment registers are used to control which segment of memory is used by the register instructions, as such the last thing you want is to load a segment register (DS in this case which is the Data Segment register) from a memory location. The act of modifying DS could cause the memory location being read to change during the process of updating DS, i.e. the first bits/byte loaded into DS now cause it to be pointing to another segment before the remainder has been read. It's safer to read the value into the Accumulator (AX) or another general purpose register, so now the value is in the processor when it's loaded into the segment register, so no chance of the value getting corrupted during the load.

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