Skip to content

Implements SBCS instruction#20

Merged
begeistert merged 4 commits into
masterfrom
feat/sbcs
Feb 15, 2026
Merged

Implements SBCS instruction#20
begeistert merged 4 commits into
masterfrom
feat/sbcs

Conversation

@lmSeryi

@lmSeryi lmSeryi commented Feb 2, 2026

Copy link
Copy Markdown
Collaborator

Adds the SBCS (Subtract with Carry) instruction to the instruction decoder and arithmetic operations.

This instruction performs subtraction with carry, taking into account the carry flag in the CPSR. A new opcode rule is added to the instruction decoder to map the instruction. Additionally, a test case is added to verify the instruction's correctness.

Description

Type of change

  • 🐛 Bug fix (non-breaking change which fixes an issue)
  • ✨ New feature (non-breaking change which adds functionality)
  • 💥 Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • 🧹 Refactoring (no functional changes, just code cleanup)

Checklist

  • 🧪 Tests passed locally (dotnet test)
  • ✅ Added new tests for this feature/fix
  • 📝 Documentation updated (if applicable)
  • 🚫 No "Magic Strings" or hardcoded values
  • 💾 Validated against the RP2040 Datasheet (if applicable)

Screenshots / Hex Dumps (Optional)

Adds the SBCS (Subtract with Carry) instruction to the instruction decoder and arithmetic operations.

This instruction performs subtraction with carry, taking into account the carry flag in the CPSR.
A new opcode rule is added to the instruction decoder to map the instruction.
Additionally, a test case is added to verify the instruction's correctness.
@lmSeryi
lmSeryi requested a review from begeistert as a code owner February 2, 2026 09:34
@lmSeryi lmSeryi self-assigned this Feb 2, 2026
Comment thread tests/RP2040.Core.Tests/Cpu/Instructions/ArithmeticOpsTests.cs
Comment thread src/RP2040.Core/Helpers/InstructionEmiter.cs Outdated
@begeistert begeistert linked an issue Feb 2, 2026 that may be closed by this pull request
5 tasks
lmSeryi and others added 3 commits February 2, 2026 23:18
Implementing test when R0 should be 0 and also checking the substraction of negative result.
Fix the subtract-with-carry (SBC) operation in ArithmeticOps.cs to use
AddWithFlags with the two's-complement operand and an explicit carry
value. Previously the code attempted to compute SBC by subtracting
(valRm + (1 - C)) via SubWithFlags, which produced incorrect flag
behavior and was harder to reason about.

Changes:
- read carry into a local uint (carry = C ? 1 : 0)
- call AddWithFlags(cpu, rdn, ~valRm, carry) to implement rdn - rm - (1 - C)
  using two's-complement addition

This makes the implementation correct for borrow/carry handling and
aligns with canonical SBC semantics while preserving CPU flags.
@sonarqubecloud

Copy link
Copy Markdown

@begeistert
begeistert merged commit f90ad35 into master Feb 15, 2026
2 checks passed
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

Successfully merging this pull request may close these issues.

[FEAT|CPU|ISA] Implement SBCS Instruction

2 participants