C to Assembly - Leaq Instruction [Duplicate]

As far as I understood:

  • %rdi = 1st argument = x
  • %rsi = 2nd argument = y
  • %rdx = 3rd argument = z
  • The others manipulate these registers... and store in a return value register

The 3rd line on the assembly code leaq (%rsi, %rsi, 2), %rdx, which as I translate it: z = y + 2*y.

I'm confused, is this code wrong, or is it an assembly magic?

5

simple explanation

it moves the address not the values

2
Sarah Jenkins

Sarah Jenkins

Senior Technology Editor & AI Specialist

Sarah Jenkins is a veteran tech journalist with over 12 years of experience covering artificial intelligence, mobile innovations, and digital ethics. Her insights have appeared in leading technology publications worldwide.

Share this article
Twitter Facebook Pinterest