Commit 16164f65b9d5d4679301faa6852b69cfa52c316e
authorMichel Pollet <buserror@gmail.com>
Mon, 7 Nov 2016 08:49:07 +0000 (08:49 +0000)
committerMichel Pollet <buserror@gmail.com>
Mon, 7 Nov 2016 08:51:36 +0000 (08:51 +0000)
As per PR #127, spliced

Signed-off-by: Michel Pollet <buserror@gmail.com>
simavr/sim/sim_core.c

index 9d46738f509aa1402bc1f48c13929f7e72249962..c40cf549ffce901eacdc2051b27a1daae5a8749d 100644 (file)
@@ -1326,7 +1326,7 @@ run_one_again:
                case 0xc000: {  // RJMP -- 1100 kkkk kkkk kkkk
                        get_o12(opcode);
                        STATE("rjmp .%d [%04x]\n", o >> 1, new_pc + o);
-                       new_pc = new_pc + o;
+                       new_pc = (new_pc + o) % (avr->flashend+1);
                        cycle++;
                        TRACE_JUMP();
                }       break;
@@ -1335,7 +1335,7 @@ run_one_again:
                        get_o12(opcode);
                        STATE("rcall .%d [%04x]\n", o >> 1, new_pc + o);
                        cycle += _avr_push_addr(avr, new_pc);
-                       new_pc = new_pc + o;
+                       new_pc = (new_pc + o) % (avr->flashend+1);
                        // 'rcall .1' is used as a cheap "push 16 bits of room on the stack"
                        if (o != 0) {
                                TRACE_JUMP();