Implement NOP
This commit is contained in:
parent
18f0a12ef5
commit
a0892109a6
|
|
@ -13,7 +13,7 @@ exports.assemble = (str, debug = false) => {
|
||||||
return decodeInstructions(str);
|
return decodeInstructions(str);
|
||||||
}
|
}
|
||||||
|
|
||||||
const mnemonicsWithOptionalArgs = ['end', 'cfc', 'chp'];
|
const mnemonicsWithOptionalArgs = ['end', 'cfc', 'chp', 'nop'];
|
||||||
const mnemonics2opcodes = {
|
const mnemonics2opcodes = {
|
||||||
end: { direct: 0, indirect: 0 },
|
end: { direct: 0, indirect: 0 },
|
||||||
sto: { direct: 1, indirect: 2 },
|
sto: { direct: 1, indirect: 2 },
|
||||||
|
|
@ -24,6 +24,7 @@ const mnemonics2opcodes = {
|
||||||
jmp: { direct: 11, indirect: 12 },
|
jmp: { direct: 11, indirect: 12 },
|
||||||
cfc: { direct: 13, indirect: 13 },
|
cfc: { direct: 13, indirect: 13 },
|
||||||
chp: { direct: 14, indirect: 14 },
|
chp: { direct: 14, indirect: 14 },
|
||||||
|
nop: { direct: 15, indirect: 15 },
|
||||||
};
|
};
|
||||||
|
|
||||||
function decodeInstructions(str) {
|
function decodeInstructions(str) {
|
||||||
|
|
|
||||||
32
readme.md
32
readme.md
|
|
@ -38,22 +38,22 @@ Assemble and run, with debug output:
|
||||||
|
|
||||||
## Instruction set
|
## Instruction set
|
||||||
|
|
||||||
0 END
|
00 END
|
||||||
1 STO lit# ; store ... mem[lit#] <- A
|
01 STO lit# ; store ... mem[lit#] <- A
|
||||||
2 STO addr ; store ... mem[mem[addr]] <- A
|
02 STO addr ; store ... mem[mem[addr]] <- A
|
||||||
3 LDA lit# ; load ... A <- lit#
|
03 LDA lit# ; load ... A <- lit#
|
||||||
4 LDA addr ; load ... A <- mem[addr]
|
04 LDA addr ; load ... A <- mem[addr]
|
||||||
5 ADD lit# ; add ... A <- A + lit# ... and un/set carry flag
|
05 ADD lit# ; add ... A <- A + lit# ... and un/set carry flag
|
||||||
6 ADD addr ; add ... A <- A + mem[addr] ... and un/set carry flag
|
06 ADD addr ; add ... A <- A + mem[addr] ... and un/set carry flag
|
||||||
7 SUB lit# ; sub ... A <- A - lit# ... and un/set carry flag
|
07 SUB lit# ; sub ... A <- A - lit# ... and un/set carry flag
|
||||||
8 SUB addr ; sub ... A <- A - mem[addr] ... and un/set carry flag
|
08 SUB addr ; sub ... A <- A - mem[addr] ... and un/set carry flag
|
||||||
9 HOP lit# ; hop ... skip next instruction if A == lit# ... when true: IP <- PC + 2
|
09 HOP lit# ; hop ... skip next instruction if A == lit# ... when true: IP <- PC + 2
|
||||||
A HOP addr ; hop ... skip next instruction if A == addr ... when true: IP <- PC + 2
|
0A HOP addr ; hop ... skip next instruction if A == addr ... when true: IP <- PC + 2
|
||||||
B JMP lit# ; jump ... IP <- lit#
|
0B JMP lit# ; jump ... IP <- lit#
|
||||||
C JMP addr ; jump ... IP <- addr
|
0C JMP addr ; jump ... IP <- addr
|
||||||
D CCF ———— ; clear Carry Flag ... CF = 0
|
0D CCF ———— ; clear Carry Flag ... CF = 0
|
||||||
E CHP ———— ; carry hop ... skip next instruction if Carry Flag is set ... when true: IP <- PC + 2
|
0E CHP ———— ; carry hop ... skip next instruction if Carry Flag is set ... when true: IP <- PC + 2
|
||||||
F
|
0F NOP ———— ; no operation
|
||||||
|
|
||||||
- Instructions are two bytes long:
|
- Instructions are two bytes long:
|
||||||
one byte for the opcode, one for the argument
|
one byte for the opcode, one for the argument
|
||||||
|
|
|
||||||
|
|
@ -147,6 +147,11 @@ const Instructions = {
|
||||||
CPU.IP += 2;
|
CPU.IP += 2;
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
|
no_op: () => {
|
||||||
|
CPU.currentInstruction.mnemonic = `NOP`;
|
||||||
|
CPU.IP += 2;
|
||||||
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
const opcodes2mnemonics = {
|
const opcodes2mnemonics = {
|
||||||
|
|
@ -165,6 +170,7 @@ const opcodes2mnemonics = {
|
||||||
12: (arg) => Instructions.jump_addr(arg),
|
12: (arg) => Instructions.jump_addr(arg),
|
||||||
13: (arg) => Instructions.carry_clear(arg),
|
13: (arg) => Instructions.carry_clear(arg),
|
||||||
14: (arg) => Instructions.carry_hop(arg),
|
14: (arg) => Instructions.carry_hop(arg),
|
||||||
|
15: (arg) => Instructions.no_op(arg),
|
||||||
};
|
};
|
||||||
|
|
||||||
function startCPU(code) {
|
function startCPU(code) {
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,6 @@
|
||||||
|
;; test NOP
|
||||||
|
ADD $01
|
||||||
|
NOP
|
||||||
|
NOP
|
||||||
|
NOP
|
||||||
|
END
|
||||||
Loading…
Reference in New Issue