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
  • 409
  • 1
  • 6
  • 16

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
  • 19
  • 3
  • 2
    Can you quote the most relevant portion of the PDF link? – Will Jan 17 '19 at 17:14
  • 3
    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
  • 3
    link to the pdf is broken – JessG Sep 30 '22 at 19:37
  • 1
    @JessG [web.archive.org](http://web.archive.org/web/20210109184422/https://web.cecs.pdx.edu/~kimchris/cs201/slides/10%20-%20x86%20Basics,%20Part%202.pdf) – kirogasa Jan 17 '23 at 02:52