简体   繁体   中英

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.

* stk = _DS;

It's comments is to get current value of 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.

In other words, a = b might be compiled as:

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

whereas a = _DS may be:

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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