1. GeneralProgramAll are relocable. The addresses of variables or functions are recorded with relative addresses. After the address of the variable is linked, you can determine the relative location. After loading, you can determine the absolute location. Generally, all functions are written as functions and modified with the modifier Proc.
2. But sometimes you need to write a non-Relocated program, you need to reference the variable with a fixed address. For example, you need to write a binfile, and then the binfile needs to be loaded to a specific address for running.
At this time, the first address needs to be written. In this way, the address is determined before compilation. Generally, tags are used, such as XXX:
At&t syntax
Org 0x100 # If this number is not specified, the default value is 0.
. Code16
Movl 0x12345678, (_ viable1)
Movl 0x12345678, (_ viable2)
_ Viable1:
. Long 0
_ Viable2:
. Long 0
If you want the ratio file to reference this variable, you can use extern, which is suitable for programming in real mode. If the protection mode is used, you need to select the Cs and DS segments to which the child points. The base address of the segment should be 0.
For example
JMP xx
Call xx
The two statements are relative displacement, that is, the new address is the following address + offset