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

Incorrect value displayed for the displacementconstant in x86 16-bit assembly - ignoring the sign bit #7139

Open
Wall-AF opened this issue Nov 2, 2024 · 2 comments

Comments

@Wall-AF
Copy link

Wall-AF commented Nov 2, 2024

Describe the bug
16-bit addressing is ignoring the sign bit of a 16-bit displacement and is consequently showing an incorrect +'ve value in it's assembly. For example Ghidra shows things like
1028:23e6 66 26 ff b7 fc f7 PUSH dword ptr ES:[BX + 0xf7fc]
instead of
1028:23e6 66 26 ff b7 fc f7 PUSH dword ptr ES:[BX + -0x804]

Expected behavior
Respect the sign of the displacement in addressing modes of x86 16-bit processors

Environment (please complete the following information):

  • OS: Windows 11
  • Java Version: Temurin-21.0.3+9
  • Ghidra Version: 11.2
  • Ghidra Origin: locally built
@GhidorahRex
Copy link
Collaborator

Since the registers are 16-bits, the result is the same, and both are semantically valid. This is complicated by the fact that some compilers use the offset as the base, so there's no precise way to know whether the intended meaning was a negative displacement or positive base address. The same is true in 32-bit mode. I believe this is why the manual specifies that disp8 should be sign-extended to 16-bits but is silent on disp16 in 16-bit mode and disp32 in 32-bit mode.

Since the are semantically equivalent, we picked a convention and stuck with it.

@Wall-AF
Copy link
Author

Wall-AF commented Nov 4, 2024

Mmm, it does make a difference, especially when the pointer (an array equivalent) is to an object of such a size that the disp16 is an exact multiple, giving Ghidra the knowledge that it's an array index!

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

No branches or pull requests

3 participants