I'm going though 'Computer Systems: A Programmer's Perspective', chapter 3 which is about machine-level representation. I'm currently on 'Arithmetic and Logic Operations', doing one of the practice problem. The problem gives C code fragment:
short scale3(short x, short y, short z){
short t = ----------------;
return t;
}
additionally i'm given an assembly code, generated from the COMPLETE code in scale3 function:
scale3:
leaq (%rsi, %rsi, 9), %rbx
leaq (%rbx, %rdx), %rbx
leaq (%rbx, %rdi, %rsi), %rbx
ret
From the generated assembly code i'm supposed to full-fill missing part in the C source code. According to X86-64 convention, i followed the rules of memory referencing and easily fond that, t(in the C code) should be assigned to -> t = 10 * y + z + y * x;. I checked the answer and it matches. Out of curiosity, i tested the code and the code generated from the function didn't match the given assembly code.
I'm working on 64-bit Linux machine, and my GCC generated the following code:
scale3:
leal 10(%rdi), %eax
imull %eax, %esi
leal (%rsi,%rdx), %eax
ret
Can anybody explain to my why i get different representations? This is probably 15th+ generate code and i've never got different result compared to the book.