Address issues in Assembler

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.