Skip to content

Commit

Permalink
feat(rp2040): implement CMP (register) encoding T2
Browse files Browse the repository at this point in the history
Still missing:

- 83 b2   uxth    r3, r0
- 50 43   muls    r0, r2
- 0b ba   rev     r3, r1
  • Loading branch information
urish committed Apr 6, 2021
1 parent afb62f2 commit 6f5e911
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 0 deletions.
13 changes: 13 additions & 0 deletions src/rp2040.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -368,6 +368,19 @@ describe('IO Register Writes', () => {
expect(rp2040.V).toEqual(false);
});

it('should execute an `cmp ip, r6` instruction', () => {
const rp2040 = new RP2040();
rp2040.PC = 0x10000000;
rp2040.flash16[0] = 0x45b4; // cmp ip (r12), r6
rp2040.registers[ip] = 60;
rp2040.registers[r6] = 56;
rp2040.executeInstruction();
expect(rp2040.N).toEqual(false);
expect(rp2040.Z).toEqual(false);
expect(rp2040.C).toEqual(true);
expect(rp2040.V).toEqual(false);
});

it('should execute an `eors r1, r3` instruction', () => {
const rp2040 = new RP2040();
rp2040.PC = 0x10000000;
Expand Down
13 changes: 13 additions & 0 deletions src/rp2040.ts
Original file line number Diff line number Diff line change
Expand Up @@ -528,6 +528,19 @@ export class RP2040 {
this.V =
(leftValue > 0 && rightValue < 0 && result < 0) ||
(leftValue < 0 && rightValue > 0 && result > 0);
// CMP (register) encoding T2
} else if (opcode >> 8 === 0b01000101) {
const Rm = (opcode >> 3) & 0xf;
const Rn = ((opcode >> 4) & 0x8) | (opcode & 0x7);
const leftValue = this.registers[Rn] | 0;
const rightValue = this.registers[Rm] | 0;
const result = (leftValue - rightValue) | 0;
this.N = leftValue < rightValue;
this.Z = leftValue === rightValue;
this.C = leftValue >= rightValue;
this.V =
(leftValue > 0 && rightValue < 0 && result < 0) ||
(leftValue < 0 && rightValue > 0 && result > 0);
} else if (opcode === 0xb672) {
console.warn('ignoring cpsid i');
} else if (opcode === 0xb662) {
Expand Down

0 comments on commit 6f5e911

Please sign in to comment.