Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
collectcrop opened this issue Feb 26, 2025 · 0 comments
Open

Comments

@collectcrop
Copy link

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant