From 7a684802ddfb9a21a9693ba62029349ab43ce1f1 Mon Sep 17 00:00:00 2001 From: Pavel Pisa Date: Tue, 20 Aug 2019 16:56:01 +0200 Subject: Implemented ASCII and ASCIZ operations. Signed-off-by: Pavel Pisa --- qtmips_asm/simpleasm.cpp | 73 +++++++++++++++++++++++++++++++++++++++++++ qtmips_gui/highlighterasm.cpp | 3 +- 2 files changed, 75 insertions(+), 1 deletion(-) diff --git a/qtmips_asm/simpleasm.cpp b/qtmips_asm/simpleasm.cpp index 5fe4573..7797a2c 100644 --- a/qtmips_asm/simpleasm.cpp +++ b/qtmips_asm/simpleasm.cpp @@ -308,6 +308,79 @@ bool SimpleAsm::process_line(QString line, QString filename, } return true; } + if ((op == ".ASCII") || (op == ".ASCIZ")) { + bool append_zero = op == ".ASCIZ"; + for (QString s: operands) { + if (s.count() < 2) { + error = "ascii empty string"; + emit report_message(messagetype::MSG_ERROR, filename, line_number, 0, error, ""); + error_occured = true; + if (error_ptr != nullptr) + *error_ptr = error; + return false; + } + if ((s.at(0) != '"') || (s.at(s.count() - 1) != '"')) { + error = "ascii missing quotes"; + emit report_message(messagetype::MSG_ERROR, filename, line_number, 0, error, ""); + error_occured = true; + if (error_ptr != nullptr) + *error_ptr = error; + return false; + } + s = s.mid(1, s.count() - 2); + for (pos = 0; pos < s.count(); pos++) { + QChar ch = s.at(pos); + if (ch == '\\') { + ch = 0; + if (pos + 1 < s.count()) switch(s.at(++pos).toLatin1()) { + case '\\': + ch = '\\'; + break; + case 'r': + ch = 0x0d; + break; + case 'n': + ch = 0x0a; + break; + case 't': + ch = 0x09; + break; + case 'b': + ch = 0x08; + break; + case '"': + ch = '"'; + break; + default: + ch = 0; + } + if (ch == '\0') { + error = "ascii - incorrect escape sequence"; + emit report_message(messagetype::MSG_ERROR, filename, line_number, 0, error, ""); + error_occured = true; + if (error_ptr != nullptr) + *error_ptr = error; + return false; + + } + } + if (!fatal_occured) + mem->write_byte(address, (uint8_t)ch.toLatin1()); + address += 1; + } + if (append_zero) { + if (!fatal_occured) + mem->write_byte(address, 0); + address += 1; + } + } + while (address & 3) { + if (!fatal_occured) + mem->write_byte(address, 0); + address += 1; + } + return true; + } std::uint32_t inst[2] = {0, 0}; ssize_t size = machine::Instruction::code_from_string(inst, 8, op, operands, error, diff --git a/qtmips_gui/highlighterasm.cpp b/qtmips_gui/highlighterasm.cpp index b996e20..8ab8abe 100644 --- a/qtmips_gui/highlighterasm.cpp +++ b/qtmips_gui/highlighterasm.cpp @@ -50,7 +50,8 @@ HighlighterAsm::HighlighterAsm(QTextDocument *parent) QStringLiteral("\\.text\\b"), QStringLiteral("\\.data\\b"), QStringLiteral("\\.globl\\b"), QStringLiteral("\\.set\\b"), QStringLiteral("\\.equ\\b"), QStringLiteral("\\.end\\b"), - QStringLiteral("\\.ent\\b") + QStringLiteral("\\.ent\\b"), QStringLiteral("\\.ascii\\b"), + QStringLiteral("\\.asciz\\b") }; for (const QString &pattern : keywordPatterns) { -- cgit v1.2.3