Skip to content

MC6800/6809: fix BGT/LBGT branch condition (uses Carry instead of Zero)#9276

Open
djmips wants to merge 1 commit into
NationalSecurityAgency:masterfrom
djmips:fix-6809-bgt-branch-condition
Open

MC6800/6809: fix BGT/LBGT branch condition (uses Carry instead of Zero)#9276
djmips wants to merge 1 commit into
NationalSecurityAgency:masterfrom
djmips:fix-6809-bgt-branch-condition

Conversation

@djmips

@djmips djmips commented Jun 14, 2026

Copy link
Copy Markdown

BGT (opcode 0x2E) and LBGT (PAGE2, op=0x2E) in Ghidra/Processors/MC6800/data/languages/6x09.sinc test the Carry flag:

if (($(N) == $(V)) & $(C)) goto REL;

Per the MC6809 programming manual, signed BGT branches on Z==0 AND (N == V); carry is not involved. This is corroborated internally by BLE (0x2F), the logical complement of BGT, which is correctly implemented as (N^V) | Z — so as written, BGT and BLE are not complements.

Example: LDX #$0060; CMPX #$005F; BGT t (96 > 95; N=V=Z=0, C=0) fails to branch.

Fix: in BGT and LBGT, replace & $(C) with & ($(Z) == 0). BGE/BLT/BLE and the long-branch forms are already correct.

Verified with gradle :MC6800:sleighCompile — all three MC6800 languages compile with no errors.

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

Labels

Feature: Processor/MC6800 Status: Triage Information is being gathered

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants