Permalink
Browse files

specced and fixed SHR

  • Loading branch information...
1 parent a2d8fbc commit f7583213a7d8ad2261d34c821af6f10387cf3576 @manuelkiessling committed Apr 20, 2012
Showing with 16 additions and 1 deletion.
  1. +1 −1 lib/Cpu.js
  2. +15 −0 spec/Cpu.spec.js
View
@@ -414,7 +414,7 @@ define([], function() {
break;
case this.opcodes['SHR']:
- this.write(target.address, target.value >> source.value);
+ this.write(target.address, (target.value >> source.value) & 0xffff);
this.registers[0x1d] = (((target.value << 16) >> source.value) & 0xffff);
break;
View
@@ -296,6 +296,21 @@ define(['../lib/Memory', '../lib/Cpu'], function(Memory, Cpu) {
});
});
+ describe('SHR', function() {
+ it('handles overflow correctly', function() {
+ var cpu = setupCpu([
+ 0x7c21, // SET C, 0xffff
+ 0xffff,
+ 0x7c28, // SHR C, 0xffff
+ 0xffff
+ ]);
+ cpu.step();
+ cpu.step();
+ expect(cpu.registers[0x02]).toEqual(0x0000);
+ expect(cpu.registers[0x1d]).toEqual(0xffff);
+ });
+ });
+
describe('IFE', function() {
it('skips the next instruction if values are not equal', function() {
var cpu = setupCpu([

0 comments on commit f758321

Please sign in to comment.