From 75af073e85476f8e79df914534721e4970fb1cc7 Mon Sep 17 00:00:00 2001 From: Pablo Parra Date: Thu, 22 Mar 2018 10:34:02 +0100 Subject: [PATCH] Added the "DW" keyword Now the user can define word-sized variables. --- src/app/app.component.ts | 4 +++- src/app/assembler.service.ts | 19 ++++++++++++++++++- 2 files changed, 21 insertions(+), 2 deletions(-) diff --git a/src/app/app.component.ts b/src/app/app.component.ts index fe9e0ce..1fddcf6 100644 --- a/src/app/app.component.ts +++ b/src/app/app.component.ts @@ -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; ' + @@ -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()) { diff --git a/src/app/assembler.service.ts b/src/app/assembler.service.ts index f0710bb..a0af1d6 100644 --- a/src/app/assembler.service.ts +++ b/src/app/assembler.service.ts @@ -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]); @@ -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') {