Skip to content

Conversation

@csoren
Copy link
Contributor

@csoren csoren commented Jan 5, 2026

Your checklist for this pull request

  • I've documented or updated the documentation of every API function and struct this PR changes.
  • I've added tests that prove my fix is effective or that my feature works (if possible)

Detailed description

In the 68K ISA, displacements can be encoded as bytes, words or longs depending on the address mode. When writing assembly code, programmers usually specify these explicitly instead of relying on the default word size. Disassemblers usually, if not always, append the size specifier to displacements.

The PR enables this functionality to be implemented, but doesn't update the built-in assembly printer. The reason for this is the way these addressing modes are currently printed - they do not follow the convention set by Motorola in the 68000 Programmer's Reference Manual. This convention will implemented as an option in a later PR. For now only the API change is implemented, as I consider these separate concerns.

Three size fields have been added - in_disp_size, out_disp_size and disp_size, which provide information about the encoded size of in_disp, out_disp and disp respectively.

Test plan

Tests of the new fields have been added to tests/details/m68k.yaml. The existing opcode stream already contains a sufficient selection of encodings.

Copy link
Collaborator

@Rot127 Rot127 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Only this nitpick. Otherwise lgtm.

@Rot127
Copy link
Collaborator

Rot127 commented Jan 5, 2026

@csoren How many changes have you still planned?
We have a release ready to go since two weeks. But I postponed it due to Christmas holidays and new year.
Now I consider to have your changes included.

@csoren
Copy link
Contributor Author

csoren commented Jan 5, 2026

The original 68000 has address modes with displacement such as $1234(a0) and $12(a0,d0.w). These are word and byte size displacements respectively. The 68020 introduced new address modes that added word and long displacements, and the syntax changed slightly to ($1234.w,a0) and ($12.b,a0,d0.w), since also ($12345678.l,a0) and ($1234.w,a0,d0.w) were possible.

Currently the printer outputs everything as $xxxx(a0,d0.w), regardless of displacement size. I would like to introduce an option to support the "new" syntax, since the current behavior is not accurate and also not correct wrt the new address modes. Additionally, some assembly language programmers prefer the old style syntax for the "old" address modes, so ideally I would also like an option for that.

Another possibility is simply to forego compatibility and change the existing printer to use the official, "new" syntax.

@Rot127
Copy link
Collaborator

Rot127 commented Jan 5, 2026

Another possibility is simply to forego compatibility and change the existing printer to use the official, "new" syntax.

I prefer the first solution. Adding an option to select the syntax.
Wdyt how long it will take?

@csoren
Copy link
Contributor Author

csoren commented Jan 5, 2026

It would be ready sometime tomorrow, January 6.

@csoren
Copy link
Contributor Author

csoren commented Jan 6, 2026

I have something that implements the official Motorola syntax. I would like to make it a separate PR once this one is approved, but I can also roll it into this one. I expect there will be a little back and forth until it is accepted, however. Let me know what you prefer.

@Rot127
Copy link
Collaborator

Rot127 commented Jan 6, 2026

Better a new one I think.

@Rot127 Rot127 merged commit 630f1ae into capstone-engine:next Jan 11, 2026
27 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants