Question

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?

Was it helpful?

Solution

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.

OTHER TIPS

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.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top