Question: I have started to learn assembly. I came across these lines.

```
;*************************************************;
; Second Stage Loader Entry Point
;************************************************;

main:
   cli  ; clear interrupts
   push cs ; Insure DS=CS
   pop ds

```

Here on second line of code, the code segment is push to the stack(I think this). I have seen it in many codes. Why we should do this and how it ensures DS =CS? On third line DS is pop out of stack(I think this). Why it is done? It is pop out of stack means it was push to stack before. There is no code for that. Can anybody explain all this to me? Thanks in advance.

Answer: 
The 'push this register onto stack, pop stack to this register' can sometimes be done with MOV instructions, such as MOV ax,dx. But some register-to-register MOV instructions aren't available in the instruction set, and IIRC MOV ds,cs isn't available. That could be the reason for putting it in memory (well, cache, really) and reading it back.
Like in the comment written, `push cs` and then `pop ds` ensures that `ds=cs?`. `push cs` puts the value of cs on the top of the stack, and then `pop ds` removes the value from the stack and stores it in `ds`.