SBC HL,rr writes its result to A instead of HL

Open Beginner friendly
#12 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
2/5
Estimated time
1-3 hours
Newbie friendliness
74/100
Issue type
Bug
Clarity
Clearly specified
Activity status
Quiet
Tech stack
python

Research direction

Start in Z80IL.py at OP.SBC and inspect how the destination register is selected for each operand size. Reproduce the ed 42 example and verify that SBC HL,BC produces a 16-bit result in HL while the existing 8-bit behavior remains correct.

Written by the indexing model from the issue text.

Description

In Z80IL.py, OP.SBC computes the subtraction at the operand size but always stores to A as one byte:

tmp = il.sub_borrow(size, lhs, rhs, il.flag("c"), flags="*")
tmp = il.set_reg(1, "A", tmp)

So ed 42 (SBC HL,BC) lifts as A = sbb.w{*}(HL, BC, flag:c) and the 16-bit result never reaches HL.

16-bit compare/subtract is common, so this silently drops pointer arithmetic — 39 sites in one test binary. Example: AND A / SBC HL,BC / LD A,(HL).

Dominant language
Python
Stars
12
Forks
5
PR merge metrics
No merged PRs in 30d

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from Vector35/Z80

All issues in Vector35/Z80

Similar issues

More Python issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.