Why do we need AX instead of MOV DS, data directly with a segment?

1.1k views Asked by At

So I was being taught the basics of how to program with Tasm (Turbo assembler 16 bits) and these two lines were explained to me, but now I can't remember why have to do it like this:

start: mov ax, data
       mov ds, ax

Why is it that we cannot set DS directly to a data segment we defined?

start: mov ds, data
2

There are 2 answers

2
David Hoelzer On BEST ANSWER

The reason that you cannot do it is not a limitation in TASM but a "feature" of the instruction set. The Intel/AMD instruction sets do not support moving an immediate value into the DS register.

It is not unusual in CISC based computers to have various restrictions and limitations. It is very useful to keep the instruction reference handy for this reason. :)

1
user19358369 On

All segment registers need to be set with a value from a non segment registers.. Segment registers include ds (data segment) es (extra segment) fs (file segment) gs (general segment) cs (code segment) and ss (stack segment).. If you want to set ds to data without disturbing your other registers consider using the following...

Push ax

Mov ax, data

Mov ds, ax

Pop ax

That will preserve the value of the ax register