0 votes
in General Knowledge by (744k points)
Consider the following code:
static int array[30]
int x = array[25]

What is the equivalent in assembler, given array is defined in .data?

1 Answer

0 votes
by (744k points)
Best answer
movq $array, %rbx (move array address to rbx)
movq $25, %rcx (move array index to rcx)
movq (%rbx, %rcx, 4), %eax (save arr[25] in eax)
movq %eax, $x (move eax into x)

Why can't we combine the last two instructions?
movq (%rbx, %rcx, 4), $x

Because we can't do memory to memory move in X86-64.
Welcome to the Answerine , a great place to find, read and share your favorite questions and answers.