File tree Expand file tree Collapse file tree 2 files changed +16
-4
lines changed Expand file tree Collapse file tree 2 files changed +16
-4
lines changed Original file line number Diff line number Diff line change @@ -469,6 +469,18 @@ describe('Cortex-M0+ Instruction Set', () => {
469469 expect ( registers . V ) . toEqual ( false ) ;
470470 } ) ;
471471
472+ it ( 'should execute an `cmp r2, r0` instruction and not set any flags when r0=0xb71b0000 and r2=0x00b71b00' , async ( ) => {
473+ await cpu . setPC ( 0x20000000 ) ;
474+ await cpu . writeUint16 ( 0x20000000 , opcodeCMPregT1 ( r2 , r0 ) ) ;
475+ await cpu . setRegisters ( { r0 : 0xb71b0000 , r2 : 0x00b71b00 } ) ;
476+ await cpu . singleStep ( ) ;
477+ const registers = await cpu . readRegisters ( ) ;
478+ expect ( registers . N ) . toEqual ( false ) ;
479+ expect ( registers . Z ) . toEqual ( false ) ;
480+ expect ( registers . C ) . toEqual ( false ) ;
481+ expect ( registers . V ) . toEqual ( false ) ;
482+ } ) ;
483+
472484 it ( 'should correctly set carry flag when executing `cmp r11, r3` instruction' , async ( ) => {
473485 await cpu . setPC ( 0x20000000 ) ;
474486 await cpu . writeUint16 ( 0x20000000 , opcodeCMPregT2 ( r11 , r3 ) ) ;
Original file line number Diff line number Diff line change @@ -1028,10 +1028,10 @@ export class RP2040 {
10281028 else if ( opcode >> 6 === 0b0100001010 ) {
10291029 const Rm = ( opcode >> 3 ) & 0x7 ;
10301030 const Rn = opcode & 0x7 ;
1031- const leftValue = this . registers [ Rn ] | 0 ;
1032- const rightValue = this . registers [ Rm ] | 0 ;
1033- const result = ( leftValue - rightValue ) | 0 ;
1034- this . N = leftValue < rightValue ;
1031+ const leftValue = this . registers [ Rn ] ;
1032+ const rightValue = this . registers [ Rm ] ;
1033+ const result = ( ( leftValue | 0 ) - ( rightValue | 0 ) ) | 0 ;
1034+ this . N = result < 0 ;
10351035 this . Z = leftValue === rightValue ;
10361036 this . C = leftValue >= rightValue ;
10371037 this . V =
You can’t perform that action at this time.
0 commit comments