From 5cf69aa5d7cab0079acec7b5ad7b70b96d01e801 Mon Sep 17 00:00:00 2001 From: Pavel Pisa Date: Thu, 22 Aug 2019 00:06:49 +0200 Subject: Implemented SKIP/SPACE assembler directives. Signed-off-by: Pavel Pisa --- qtmips_asm/simpleasm.cpp | 62 +++++++++++++++++++++++++++++++++++++++++++ qtmips_gui/highlighterasm.cpp | 3 ++- 2 files changed, 64 insertions(+), 1 deletion(-) diff --git a/qtmips_asm/simpleasm.cpp b/qtmips_asm/simpleasm.cpp index e62ee00..0deea6f 100644 --- a/qtmips_asm/simpleasm.cpp +++ b/qtmips_asm/simpleasm.cpp @@ -266,6 +266,68 @@ bool SimpleAsm::process_line(QString line, QString filename, address = value; return true; } + if ((op == ".SPACE") || (op == ".SKIP")) { + bool ok; + fixmatheval::FmeExpression expression; + fixmatheval::FmeValue value; + fixmatheval::FmeValue fill = 0; + if ((operands.count() != 1) && (operands.count() != 2)) { + error = ".space/.skip unexpected number of operands"; + emit report_message(messagetype::MSG_ERROR, filename, line_number, 0, error, ""); + error_occured = true; + if (error_ptr != nullptr) + *error_ptr = error; + return false; + } + if (operands.count() > 1) { + ok = expression.parse(operands.at(1), error); + if (!ok) { + fatal_occured = true; + error = tr(".space/.skip %1 parse error.").arg(line); + emit report_message(messagetype::MSG_ERROR, filename, line_number, 0, error, ""); + error_occured = true; + if (error_ptr != nullptr) + *error_ptr = error; + return false; + } + ok = expression.eval(fill, symtab, error); + if (!ok) { + fatal_occured = true; + error = tr(".space/.skip %1 evaluation error.").arg(line); + emit report_message(messagetype::MSG_ERROR, filename, line_number, 0, error, ""); + error_occured = true; + if (error_ptr != nullptr) + *error_ptr = error; + return false; + } + } + ok = expression.parse(operands.at(0), error); + if (!ok) { + fatal_occured = true; + error = tr(".space/.skip %1 parse error.").arg(line); + emit report_message(messagetype::MSG_ERROR, filename, line_number, 0, error, ""); + error_occured = true; + if (error_ptr != nullptr) + *error_ptr = error; + return false; + } + ok = expression.eval(value, symtab, error); + if (!ok) { + fatal_occured = true; + error = tr(".space/.skip %1 evaluation error.").arg(line); + emit report_message(messagetype::MSG_ERROR, filename, line_number, 0, error, ""); + error_occured = true; + if (error_ptr != nullptr) + *error_ptr = error; + return false; + } + while (value-- > 0) { + if (!fatal_occured) + mem->write_byte(address, (uint8_t)fill); + address += 1; + } + return true; + } if ((op == ".EQU") || (op == ".SET")) { if ((operands.count() > 2) || (operands.count() < 1)) { error = tr(".set or .equ incorrect arguments number."); diff --git a/qtmips_gui/highlighterasm.cpp b/qtmips_gui/highlighterasm.cpp index c9d16d2..e154b1f 100644 --- a/qtmips_gui/highlighterasm.cpp +++ b/qtmips_gui/highlighterasm.cpp @@ -51,7 +51,8 @@ HighlighterAsm::HighlighterAsm(QTextDocument *parent) QStringLiteral("\\.globl\\b"), QStringLiteral("\\.set\\b"), QStringLiteral("\\.equ\\b"), QStringLiteral("\\.end\\b"), QStringLiteral("\\.ent\\b"), QStringLiteral("\\.ascii\\b"), - QStringLiteral("\\.asciz\\b"), QStringLiteral("\\.byte\\b") + QStringLiteral("\\.asciz\\b"), QStringLiteral("\\.byte\\b"), + QStringLiteral("\\.skip\\b"), QStringLiteral("\\.space\\b") }; for (const QString &pattern : keywordPatterns) { -- cgit v1.2.3