Skip to content

Commit

Permalink
Fix sta decoding issue
Browse files Browse the repository at this point in the history
  • Loading branch information
eliben committed Jun 28, 2021
1 parent 7a0c9bf commit fffa745
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 2 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,6 @@
},
"homepage": "https://github.com/eliben/js-8080-sim#readme",
"devDependencies": {
"mocha": "^8.0.1"
"mocha": "^8.4.0"
}
}
2 changes: 1 addition & 1 deletion src/assembler.js
Original file line number Diff line number Diff line change
Expand Up @@ -386,7 +386,7 @@ class Assembler {
}
case 'sta': {
this._expectArgsCount(sl, 1);
let num = this._argImmOrLabel(sl, sl.args[1], curAddr);
let num = this._argImmOrLabel(sl, sl.args[0], curAddr);
// 16-bit immediates encoded litte-endian.
return [0b00110010, num & 0xff, (num >> 8) & 0xff];
}
Expand Down
19 changes: 19 additions & 0 deletions test/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -283,6 +283,25 @@ describe('sim', () => {
assert.equal(state.a, 33);
});

it('lda-sta', () => {
let [state, mem] = runProg(`
lda myArray
mov c, a
mvi a, 99
sta myArray
mvi a, 0
lda myArray
hlt
myArray:
db 33
`);

assert.ok(state.halted);
assert.equal(state.c, 33);
assert.equal(state.a, 99);
});

it('array-dw', () => {
let [state, mem, labelToAddr] = runProg(`
hlt
Expand Down

0 comments on commit fffa745

Please sign in to comment.