c++ – Explain the asma exhaust: where $ 8583909746840200520 comes from when creating "Hello, world! \ N"

Question:

I cannot understand the assembler code obtained as a result of compiling the simplest program:

int main(int argc, char* argv[]) {
    char str[] = "Hello, world!\n";
}

Using gcc6.3 x86_64 gives the following result:

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 ?

Note that if you write like 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

Answer:

8583909746840200520 (dec) == 77202C6F6C6C6548 (hex) == "w, olleH" (str), the second giant number is the rest of the string.

Scroll to Top