Simple assembly question.

Asked 2 years ago, Updated 2 years ago, 114 views

#include <stdio.h>

int main() {
    int a = 20;
    int b = 10;

    int r = a / b; (#)

    printf("%d\n", r);

    return 0;
}

If you disable the # part here, it is shown below.

int r = a / b;
    0x8000660 mov -0xc(%rbp),%eax
    0x8000663 cltd
    0x8000664 idivl -0x8(%rbp)
    0x8000667 mov %eax,-0x4(%rbp)

I understand everything else, but the command cltd is a little hard to understand. I looked it up on the Internet and it said that it is a command to expand the 4-byte long data type to the 8-byte double data type, but what variable is the data type in this code specifically?

assembly gnu

2022-09-22 19:14

1 Answers

The reason for using cltd mnemonic is that you need 8 bytes to divide.

In particular, if the divisor is 32-bit, you need a 64-bit size fidget number to get a share.

64-bit/32-bit = 32-bit. In other words, we need 8 bytes because of the subject number a, so we expand it.


2022-09-22 19:14

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.