简体   繁体   English

谁能告诉我它是如何得到寄存器DS的值的

[英]Who can tell me that how could it get the value of register DS

In the source of uc/os, I couldn't understand the following code.在uc/os的源码中,看不懂下面的代码。

* stk = _DS; * stk = _DS;

It's comments is to get current value of DS.它的注释是获取 DS 的当前值。

Can you tell me why?你能告诉我为什么吗?

Almost certainly, the compiler recognises _DS as a special "variable" and, instead of extracting the contents of that variable from wherever variables are stored, it just uses the contents of the data segment register directly.几乎可以肯定,编译器将_DS识别为一个特殊的“变量”,而不是从存储变量的地方提取该变量的内容,它只是直接使用数据段寄存器的内容。

In other words, a = b might be compiled as:换句话说, a = b可以编译为:

mov  ax, [0x12341234] // assuming b is at this location.
mov  [0x56785678], ax // assuming a is at this location.

whereas a = _DS may be:a = _DS可能是:

push ds               // or, if available: mov ax, ds
pop ax
mov  [0x56785678], ax // assuming a is at this location.

It's a compiler defined macro (I assume this due to the upper case only name).这是一个编译器定义的宏(我假设这是由于名称只有大写)。 The leading _ usually tells you it being compiler specific.前导_通常告诉您它是特定于编译器的。 So once the preprocessor runs it will insert its own code that will essentially return the current value of DS.因此,一旦预处理器运行,它将插入自己的代码,该代码实际上将返回 DS 的当前值。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM