汇编器mov问题

发布于 2024-09-18 11:44:00 字数 403 浏览 3 评论 0原文

我有下一个代码:

mov  ax,@data
mov  ds,ax

为什么我不能这样写?

mov ds,@data

全部来源:

   .MODEL small
   .STACK 100h
   .DATA
   HelloMessage DB 'Hello, world',13,10,'$'
   .CODE 
   .startup
   mov  ax,@data
   mov  ds,ax
   mov  ah,9
   mov  dx,OFFSET HelloMessage
   int  21h
   mov  ah,4ch
   int  21h
   END

谢谢!

I have the next code:

mov  ax,@data
mov  ds,ax

Why I can not write just like this?

mov ds,@data

All source:

   .MODEL small
   .STACK 100h
   .DATA
   HelloMessage DB 'Hello, world',13,10,'

Thank you!

.CODE .startup mov ax,@data mov ds,ax mov ah,9 mov dx,OFFSET HelloMessage int 21h mov ah,4ch int 21h END

Thank you!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

驱逐舰岛风号 2024-09-25 11:44:00

你不能,因为指令集不包含执行此操作的指令。这只是 x86 的众多特性之一。

对于汇编语言来说,这些限制是相当正常的。大多数架构都包含一些经过特殊处理的寄存器(例如处理器状态字),但通常少于 x86 架构。

不为所有可能的移动提供指令的原因是为了减少指令集的大小,以便指令占用更少的内存。总体而言,分两步完成很少需要的动作会更有效。

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.

阳光①夏 2024-09-25 11:44:00

通用寄存器作为“ax”被设计为保存指向数据的16位数字(在您的情况下是DATA内部的字符串)

所以如果您尝试直接将数据传递到特殊寄存器(此处为ds或数据段)它不会正常工作,因为它不知道以这种方式接受数据。因此,我们首先获取该“数字”或数据开始的内存位置点。将该点传递给 ds 寄存器。

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.

拥抱我好吗 2024-09-25 11:44:00

我不是专家,但这就是我对这种限制的理解。

段寄存器用于控制寄存器指令使用哪个内存段,因此您最不想做的就是从内存位置加载段寄存器(在本例中为 DS,即数据段寄存器)。修改 DS 的行为可能会导致正在读取的内存位置在更新 DS 的过程中发生变化,即加载到 DS 中的第一个位/字节现在导致它在读取其余部分之前指向另一个段。将值读入累加器 (AX) 或另一个通用寄存器会更安全,因此现在该值在加载到段寄存器时位于处理器中,因此在加载过程中该值不会被损坏。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文