2

Why do we copy CS into DS in 8086?

Copy CS into DS:

    MOV AX,CS;
    MOV DS,AX;

Why do we need to do that?

cf-
  • 8,598
  • 9
  • 36
  • 58
  • 1
    possible duplicate of [Why does the mov instruction have to be used this way?](http://stackoverflow.com/questions/928082/why-does-the-mov-instruction-have-to-be-used-this-way) – Damien_The_Unbeliever May 14 '14 at 08:56
  • 6
    This question needs more context. You copy CS to DS because you want to copy CS to DS. It's like asking why you increment a variable. – Raymond Chen May 14 '14 at 09:07
  • 1
    Probably to access data that we know is in our code segment. (you may see it done as `push cs` \ `pop ds` also) – Frank Kotler May 14 '14 at 09:14

2 Answers2

3

Short answer is: to avoid using cs: prefix when we accessing code memory as data memory.

Check x86 memory segmentation to understand this.

GJ.
  • 10,810
  • 2
  • 45
  • 62
1

This is normally done in "tiny" model, which in DOS is a .COM program (the program starts at offset hex 100). Both code and data share the same segment space, although the code may change this later. For other models ("small", "medium", "large"), which in DOS is a .EXE program, there are separate segments, so DS is loaded with a value that corresponds to the data segment of a program.

rcgldr
  • 27,407
  • 3
  • 36
  • 61