1

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?

enter image description here

dud3
  • 331
  • 1
  • 4
  • 14

1 Answers1

1

https://web.cecs.pdx.edu/~kimchris/cs201/slides/10%20-%20x86%20Basics,%20Part%202.pdf

simple explanation

it moves the address not the values

Arun Kumar
  • 11
  • 3
  • 1
    Can you quote the most relevant portion of the PDF link? – Will Jan 17 '19 at 17:14
  • 2
    leaq (%rsi, %rsi, 2), %rdx means %rdx=2*rsi+rsi which is equal to 3*rsi in binary we write 3 as 000011 so after 4 left sfift (sal-shift acc. left) 110000 which is 48 – Arun Kumar Jan 17 '19 at 21:00