Skip to content

Commit

Permalink
Added the "DW" keyword
Browse files Browse the repository at this point in the history
Now the user can define word-sized variables.
  • Loading branch information
parraman committed Mar 22, 2018
1 parent 97255e6 commit 75af073
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 2 deletions.
4 changes: 3 additions & 1 deletion src/app/app.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ export class AppComponent implements AfterViewInit {

private sample4 = '; Example 4:\n; Program a periodic interrupt that increments\n; a counter [0 to ' +
'99] and prints its value into\n; the textual display\n \n\tJMP start\n\tJMP ' +
'isr\n\ncounter:\t\t; the counter\n\tDB 0\n\tDB 0\n\nstart:\n\tMOV SP, 255\t\t; ' +
'isr\n\ncounter:\t\t; the counter\n\tDW 0\n\nstart:\n\tMOV SP, 255\t\t; ' +
'Set SP\n\tMOV A, 2\t\t; Set bit 1 of IRQMASK\n\tOUT 0\t\t\t; Unmask timer ' +
'IRQ\n\tMOV A, 0x20\t\t; Set timer preload\n\tOUT 3\n\tSTI\n\tHLT\n\nisr:\n\tPUSH ' +
'A\n\tPUSH B\n\tPUSH C\n\tMOV A, [counter]\t; Increment the\n\tINC A\t\t\t\t; ' +
Expand Down Expand Up @@ -240,6 +240,8 @@ export class AppComponent implements AfterViewInit {
}

start.push({regex: /DB\b/, token: 'keyword'});
start.push({regex: /DW\b/, token: 'keyword'});
start.push({regex: /ORG\b/, token: 'keyword'});

for (const item of instructionSet.getMnemonics()) {

Expand Down
19 changes: 18 additions & 1 deletion src/app/assembler.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -402,7 +402,8 @@ export class AssemblerService {
}

if (p1.type === OperandType.NUMBER) {
this.code.push(p1.value);
p1.type = AssemblerService.checkOperandTypeValue(OperandType.BYTE, p1.value);
this.pushOperandToCode(p1);
} else if (p1.type === OperandType.ARRAY) {
for (let j = 0, k = p1.value.length; j < k; j++) {
this.code.push(p1.value[j]);
Expand All @@ -411,6 +412,22 @@ export class AssemblerService {
throw {error: 'DB does not support this operand', line: i + 1};
}

continue;
} else if (instr === 'DW') {

try {
p1 = AssemblerService.getValue(match[OP1_GROUP]);
} catch (e) {
throw {error: e.toString(), line: i + 1};
}

if (p1.type === OperandType.NUMBER) {
p1.type = AssemblerService.checkOperandTypeValue(OperandType.WORD, p1.value);
this.pushOperandToCode(p1);
} else {
throw {error: 'DW does not support this operand', line: i + 1};
}

continue;
} else if (instr === 'ORG') {

Expand Down

0 comments on commit 75af073

Please sign in to comment.