asked 35.8k views
3 votes
How do you write the following expressions in X86-64? (assume array is of ints, or 4 byte values)

1. E
2. E[i]
3. (E[i])
4. E+i-1
5. *(E+i-3)

Suppose rdx holds the starting address of array E and rcx holds the integer index i.

1 Answer

7 votes

Final answer:

To write expressions in X86-64, you can access single variables using their names and access elements in an array by using the base address and the index multiplied by the size of each element. Parentheses do not affect the syntax, and offsets can be added or subtracted from the base address. An asterisk before an expression indicates accessing the value at that address.

Step-by-step explanation:

To write the expressions in X86-64, we need to understand how memory is accessed in the language.

  1. E: In X86-64, accessing a single variable is done simply by using its name.
  2. E[i]: To access an element in an array, we use the base address of the array (rdx in this case) and add the index multiplied by the size of each element (4 in this case).
  3. (E[i]): Adding parentheses around an expression does not change how it is written in X86-64.
  4. E+i-1: To calculate an address by adding or subtracting an offset, we again use the base address of the array (rdx) and add the offset multiplied by the size of each element.
  5. *(E+i-3): The asterisk (*) before (E+i-3) indicates that we want to access the value stored at the calculated address.
answered
User Brian Sanchez
by
8.2k points

Related questions

1 answer
2 votes
222k views
asked Apr 22, 2023 26.6k views
Hashbang asked Apr 22, 2023
by Hashbang
8.0k points
1 answer
0 votes
26.6k views