Skip to content

Implement TST instruction #19

Merged
lmSeryi merged 2 commits into
masterfrom
feat/tst
Feb 9, 2026
Merged

Implement TST instruction #19
lmSeryi merged 2 commits into
masterfrom
feat/tst

Conversation

@begeistert

Copy link
Copy Markdown
Collaborator

Description

  • Implement TST (Rn, Rm): BitOps.Tst computes Rn & Rm and updates N and Z flags.
  • Add InstructionDecoder rule mapping 0x4200 pattern to BitOps.Tst.
  • Add InstructionEmitter.Tst to emit 16-bit TST opcode for low registers with validation.
  • Tighten low-register validation in InstructionEmitter.Rsbs to throw LowRegisterIndexOutOfRange for out-of-range low-registers.
  • Add unit tests: BitOpsTests for TST flag behavior (negative and zero) and InstructionDecoder tests for Rev16, Movs, and Tst to improve coverage and ensure correct encodings.

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)

Add implementation and decoding for the TST (Rn, Rm) instruction, including:
- Instruction handler in BitOps.Tst that computes Rn & Rm and updates
  the N and Z flags.
- Opcode rule for TST in InstructionDecoder to route 0x4200 pattern to
  BitOps.Tst.
- InstructionEmiter.Tst helper to emit the 16-bit TST opcode for low
  registers and argument validation for low-register constraints.

Add unit tests in BitOpsTests:
- Should_SetNegativeFlag_When_ResultHasSignBitSet verifies N is set when
  the bitwise AND has the sign bit.
- Should_SetZeroFlag_When_ResultIsZero verifies Z is set when result is
  zero.

Tighten register index validation in InstructionEmiter.Rsbs:
- Change high/low register bounds checks to use low-register range (0-7)
  and throw LowRegisterIndexOutOfRange for low-register encodings.

These changes implement bit-test functionality, ensure the decoder
recognizes the instruction, and add tests to validate flag behavior.
Add unit tests for three previously untested ARM instructions in the
InstructionDecoder suite: Rev16, Movs and Tst. These are added alongside
existing bit-op and move variations to ensure the decoder emits the
correct encodings and the corresponding BitOps handlers are validated.

This improves coverage for byte/halfword reversal and flag-affecting
move/test operations, catching decoder regressions and aligning tests
with implemented instruction emitters.
@begeistert
begeistert requested a review from lmSeryi as a code owner February 2, 2026 09:14
@sonarqubecloud

sonarqubecloud Bot commented Feb 2, 2026

Copy link
Copy Markdown

@begeistert begeistert changed the title feat/tst Implement TST instruction Feb 2, 2026
@begeistert begeistert self-assigned this Feb 2, 2026
@lmSeryi
lmSeryi merged commit 3ad2278 into master Feb 9, 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.

2 participants