Change address values (, % EDI, 4) and change address 4 (% EDI)

Source: Internet
Author: User

Assembly Language Programming by Richard BLUM: 5.2.4 transfer data between memory and registers

 

Memory location with address change:

You can specify to store multiple values in the memory in one command:

Values:

. Int 10, 15, 20, 25, 30, 35, 40, 45, 50, 55, 60

This creates a series of continuous data values stored in the memory. Each data value occupies a unit of memory (in the above example, it is a long integer, that is, 4 bytes ). When referencing data in an array, you must use the address change system to determine which value you want to access.

The method for completing this operation is called the address change memory mode (indexed memory mode ). The memory location is determined by the following factors:

(1) base address

(2) The offset address added to the base address

(3) determine the data element (number of) to be selected.

(4) length of data elements

The expression format is:

Base_address (offset_address, index, size)

The obtained data value is located:

Base_address + offset_address + Index * size

If any of the values is zero, you can ignore them (but you still need to use commas as placeholders ). The offset_address and index values must be registers, but the size value can be numeric values. For example, to reference the value 20 in the previous values array, you can use the following command:

Movl $2, % EDI

Movl values (, % EDI, 4), % eax

This command loads the 3rd 4-byte address change value starting from the values tag to the eax register (Remember, the array starts from the address 0 ).

 

Use register indirect addressing

In addition to data storage, registers can also be used to store memory addresses. When the register stores the memory address, it is called a pointer ). Using pointers to access data stored in memory is called indirect addressing ).

Use tags to reference data values contained in memory locations,Address of the memory location where the data value is obtained by adding the dollar sign ($) to the front of the tag. Therefore, the following command

Movl $ values, % EDI

The address used to transmit the memory location referenced by the values tag to the EDI register.

The other half of the indirect addressing mode, as shown in the following command.

Movl % EBX, (% EDI)

If there are no parentheses outside the EDI register, the command simply loads the values in the EBX Register into the EDI register.If the EDI register is enclosed in parentheses, the instruction transfers the values in the EBX register to the memory location contained in the EDI register.

The GNU assembler does not allow adding values to registers. values must be placed out of brackets., Like this:

Movl % edX, 4 (% EDI)

This command stores the value in the edx register in the memory position four bytes after the location pointed by the EDI register. You can also store it in the opposite direction:

 

Movl % edX,-4 (% EDI)

 

This command stores the value in the memory location four bytes before the location pointed by the EDI register.

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.