Skip to content

2.6:The statement that inc rax takes 1 byte in x86 is incorrect. #329

Open
@collectcrop

Description

@collectcrop

in section 2.6,you noted "something simple and very common like inc rax takes one byte".

In the x86_64 architecture, the machine code for the inc rax instruction is actually \x48\xff\xc0 and inc eax is \xff\xc0, which is not 1 byte long. The confusion likely arises from mixing up with the 32-bit version of the instruction.

In the x86 (32-bit) architecture, the instruction inc eax has the machine code \x40, which is indeed 1 byte. However, when moving to the x86_64 (64-bit) architecture, the instruction inc rax requires a REX prefix (\x48), followed by \xff\xc0, making the total size 3 bytes.

To clarify:

In x86 (32-bit): inc eax machine code is \x40 (1 byte).
In x86_64 (64-bit): inc rax machine code is \x48\xff\xc0 (3 bytes), with the \x48 prefix indicating the use of the 64-bit register (rax instead of eax).
This distinction is important for understanding how machine code differs between 32-bit and 64-bit architectures. Therefore, the statement that "inc rax takes 1 byte" should be corrected to reflect that it actually requires 3 bytes in x86_64.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions