1

The following GNU Assembly example for x86 is taken from the book "Programming from the Ground Up":

      1 #VARIABLES: The registers have the following uses:
      2 #
      3 # %edi - Holds the index of the data item being examined
      4 # %ebx - Largest data item found
      5 # %eax - Current data item
      6 #
      7 # The following memory locations are used:
      8 #
      9 # data_items - contains the item data. A 0 is used
     10 # to terminate the data
     11
     12 .section .data
     13
     14 data_items:
     15  .long 3,67,34,222,45,75,54,34,44,33,22,11,66,0
     16
     17 .section .text
     18
     19 .globl _start
     20
     21 _start:
     22  movl $0, %edi                    #move a 0 into the edi register
     23  movl data_items(,%edi,4), %eax   #load the first byte of data
     24  movl %eax, %ebx

I'm struggling to understand the syntax of line 23. Looking at the syntax I can deduce the following:

  • movl command moves the list contents in the location designated by data_items to register eax.

But I'm not sure how to exactly understand the notation "(,%edi,4)", i.e:

  • why is there an empty argument there in the list of arguments?
  • what is the 4 for?

How would I read out in human language line 23 so that it makes consistent sense?

Peter Cordes
  • 328,167
  • 45
  • 605
  • 847
Traiano Welcome
  • 783
  • 2
  • 12
  • 24
  • 2
    Does this answer your question? [Assembly: What is the purpose of movl data\_items(,%edi,4), %eax in this program](https://stackoverflow.com/questions/48178969/assembly-what-is-the-purpose-of-movl-data-items-edi-4-eax-in-this-program) – Paweł Łukasik Jan 01 '20 at 14:15
  • Oh good grief, yes. Thanks @PawełŁukasik – Traiano Welcome Jan 01 '20 at 14:23

0 Answers0