I can not understand the assembler code resulting from the compilation of the simplest program:
int main(int argc, char* argv[]) { char str[] = "Hello, world!\n"; } When using gcc6.3 x86_64 , the result is:
main: pushq %rbp movq %rsp, %rbp movl %edi, -20(%rbp) movq %rsi, -32(%rbp) movabsq $8583909746840200520, %rax movq %rax, -16(%rbp) movl $1684828783, -8(%rbp) movw $2593, -4(%rbp) movb $0, -2(%rbp) movl $0, %eax popq %rbp ret Where $8583909746840200520 ?
I note that if you write this:
int main(int argc, char* argv[]) { char str[] = "Hello, world!\0"; } it turns out quite different:
.LC0: .string "Hello, world!" .string "" main: pushq %rbp movq %rsp, %rbp movl %edi, -20(%rbp) movq %rsi, -32(%rbp) movq .LC0(%rip), %rax movq %rax, -16(%rbp) movl .LC0+8(%rip), %eax movl %eax, -8(%rbp) movzwl .LC0+12(%rip), %eax movw %ax, -4(%rbp) movzbl .LC0+14(%rip), %eax movb %al, -2(%rbp) movl $0, %eax popq %rbp ret
strformally a string. In the second - is not formally. It is clear that this difference is not a reason for the difference in such "doing nothing" code, but nonetheless. Yes, and there is a suspicion that the code was compiled without optimizations, which makes the question of the difference meaningless. - AnT