Cosa fa il cltq in assembly?

0x0000000000400553 : mov -0x4(%rbp),%eax 0x0000000000400556 : cltq 0x0000000000400558 : shl $0x3,%rax 0x000000000040055c : mov %rax,%rdx 

In realtà il mio programma è semplice come:

 5 int main(int argc, char *argv[]) { 6 int i = 0; 7 while(environ[i]) { 8 printf("%s\n", environ[i++]); 9 } 10 return 0; 

Ma l’output dell’assieme è piuttosto lungo:

 Dump of assembler code for function main: 0x0000000000400518 : push %rbp 0x0000000000400519 : mov %rsp,%rbp 0x000000000040051c : sub $0x20,%rsp 0x0000000000400520 : mov %edi,-0x14(%rbp) 0x0000000000400523 : mov %rsi,-0x20(%rbp) 0x0000000000400527 : movl $0x0,-0x4(%rbp) 0x000000000040052e : jmp 0x400553  0x0000000000400530 : mov -0x4(%rbp),%eax 0x0000000000400533 : cltq 0x0000000000400535 : shl $0x3,%rax 0x0000000000400539 : mov %rax,%rdx 0x000000000040053c : mov 0x2003e5(%rip),%rax # 0x600928  0x0000000000400543 : lea (%rdx,%rax,1),%rax 0x0000000000400547 : mov (%rax),%rdi 0x000000000040054a : addl $0x1,-0x4(%rbp) 0x000000000040054e : callq 0x400418  0x0000000000400553 : mov -0x4(%rbp),%eax 0x0000000000400556 : cltq 0x0000000000400558 : shl $0x3,%rax 0x000000000040055c : mov %rax,%rdx 0x000000000040055f : mov 0x2003c2(%rip),%rax # 0x600928  0x0000000000400566 : lea (%rdx,%rax,1),%rax 0x000000000040056a : mov (%rax),%rax 0x000000000040056d : test %rax,%rax 0x0000000000400570 : jne 0x400530  0x0000000000400572 : mov $0x0,%eax 0x0000000000400577 : leaveq 0x0000000000400578 : retq End of assembler dump. 

Quello che non capisco è questo blocco:

 0x000000000040052e : jmp 0x400553  0x0000000000400530 : mov -0x4(%rbp),%eax 0x0000000000400533 : cltq 0x0000000000400535 : shl $0x3,%rax 0x0000000000400539 : mov %rax,%rdx 0x000000000040053c : mov 0x2003e5(%rip),%rax # 0x600928  0x0000000000400543 : lea (%rdx,%rax,1),%rax 0x0000000000400547 : mov (%rax),%rdi 0x000000000040054a : addl $0x1,-0x4(%rbp) 0x000000000040054e : callq 0x400418  0x0000000000400553 : mov -0x4(%rbp),%eax 0x0000000000400556 : cltq 0x0000000000400558 : shl $0x3,%rax 0x000000000040055c : mov %rax,%rdx 0x000000000040055f : mov 0x2003c2(%rip),%rax # 0x600928  0x0000000000400566 : lea (%rdx,%rax,1),%rax 0x000000000040056a : mov (%rax),%rax 0x000000000040056d : test %rax,%rax 0x0000000000400570 : jne 0x400530