V
V
Vi2016-02-07 23:51:46
Programming
Vi, 2016-02-07 23:51:46

Question about segment registers and DS register loading process?

In assembler textbooks, you can see the following code for the exe program
.Data
name db 'name'
.Code
mov ax,@Data
mov ds,ax
ret
etc ......
I can not understand where the value of this register (DS) comes from can know where her data will be in order to indicate this value herself?

Answer the question

In order to leave comments, you need to log in

3 answer(s)
J
jcmvbkbc, 2016-02-08
@redsabien

how can the program know where its data will be in order to indicate this value itself?

It cannot know before loading, so all segment parts of addresses are written as offsets relative to the beginning of the program, i.e. as if the program will be loaded at address 0. The EXE file contains a relocation table, this is an array of offsets relative to the beginning of the program, at which the segment parts of the addresses are located. The EXE loader iterates over this array and adds to the words in memory the actual segment address at which the program is loaded.

A
Armenian Radio, 2016-02-08
@gbg

Registers before starting the program sets DOS.

A
Alexander Polyakov, 2016-02-08
@MakedonskyLF

As they say, according to the principles of von Neumann, the program and data are not indistinguishable from each other. Accordingly, starting your program comes down to the fact that the launching program sets the code segment pointer to the beginning of your code. And then your program should spin as it can.
You write the program, then the compiler compiles it (yes, it doesn't sound very good). The compiler introduced such a simplification that you can specify the address of the data segment with the "@Data" construct. In a compiled program, this will be a constant, i.e. during compilation, the compiler itself will determine and substitute this constant.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question