cucos

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?


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.