i8085
v0.2.0
Published
Lexer, Parser, Assembler, and Processor for Intel 8085 implemented in TypeScript.
Maintainers
Readme
i8085
Lexer, Parser, Assembler, and Processor for Intel 8085 implemented in TypeScript.
Example
Sample Code:
import { Lexer } from 'i8085/lexer';
import { Parser } from 'i8085/parser';
import { Assembler } from 'i8085/assembler';
const code = `
MVI B, 10H
HLT
`;
const lexer = new Lexer(code);
const tokens = lexer.tokenize();
console.log(tokens);
const parser = new Parser(tokens);
const ast = parser.parse();
console.dir(ast, { depth: 10 });
const assembler = new Assembler(ast);
console.dir(assembler.assemble(), { depth: 10 });Output:
[
{ col: 1, line: 1, printValue: '\n', type: 'Newline', value: '\n' },
{ col: 1, line: 2, printValue: 'MVI', type: 'Opcode', value: 'MVI' },
{ col: 5, line: 2, printValue: 'B', type: 'Register', value: 'B' },
{ col: 6, line: 2, printValue: ',', type: 'Comma', value: ',' },
{
base: 'Hex',
col: 8,
line: 2,
printValue: '10H',
type: 'Number',
value: '10H'
},
{ col: 11, line: 2, printValue: '\n', type: 'Newline', value: '\n' },
{ col: 1, line: 3, printValue: 'HLT', type: 'Opcode', value: 'HLT' },
{ col: 4, line: 3, printValue: '\n', type: 'Newline', value: '\n' },
{ col: 1, line: 4, printValue: '', type: 'EOF', value: '' }
]
{
program: [
{
instruction: {
label: null,
opcode: {
col: 1,
line: 2,
printValue: 'MVI',
type: 'Opcode',
value: 'MVI'
},
operandsPattern: 'Reg_Byte',
operandOne: {
col: 5,
line: 2,
printValue: 'B',
type: 'Register',
value: 'B'
},
operandTwo: {
base: 'Hex',
col: 8,
line: 2,
printValue: '10H',
type: 'Number',
value: '10H'
}
},
type: 'Instruction'
},
{
instruction: {
label: null,
opcode: {
col: 1,
line: 3,
printValue: 'HLT',
type: 'Opcode',
value: 'HLT'
},
operand: null,
operandsPattern: 'None'
},
type: 'Instruction'
}
]
}
Map(3) { '0003' => '06', '0004' => '10', '0005' => '76' }