Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Initializing the data segment Register in assembly 8086 using masm compiler

The following two statements for initializing the data segment register

    mov AX, @Data  
    mov DS, AX

but the actual data segment address is known only when the loader loads the program in memory.
- What does the assembler puts in place of @data?
- When the loader gets the actual data segment base address does it replace the instruction mov AX, @data with the mov AX, Actual Base Address?
- Why it is necessary to write this statement when the actual base address is not known before the loading stage?

like image 855
user2277648 Avatar asked May 14 '26 04:05

user2277648


1 Answers

Each time you write an instruction like mov AX, @Data the compiler/assembler inserts 3 bytes in your program:

  • The 1st byte is the opcode, in case of AX it will be 0B8h
  • The 2nd and 3rd bytes together represent a number.
  • What does the assembler puts in place of @data?

This number represents the distance between the start of the executable (when loaded in memory) and the start of the data section. This number is expressed in paragraphs aka chunks of 16 bytes.

  • When the loader gets the actual data segment base address does it replace the instruction mov AX, @data with the mov AX, Actual Base Address?

The loader only updates the 2nd and 3rd bytes. It never touches the 1st byte!

  • Why it is necessary to write this statement when the actual base address is not known before the loading stage?

Everywhere your write these instructions (there can be many of these), you provide DOS with placeholders where the DOS loader can insert the correct addresses.

like image 133
Sep Roland Avatar answered May 18 '26 18:05

Sep Roland