diff options
author | Pavel Pisa <pisa@cmp.felk.cvut.cz> | 2019-08-20 16:56:01 +0200 |
---|---|---|
committer | Pavel Pisa <pisa@cmp.felk.cvut.cz> | 2019-08-20 16:56:01 +0200 |
commit | 7a684802ddfb9a21a9693ba62029349ab43ce1f1 (patch) | |
tree | 06470fb1f6552f16bad1fae6a4aa143608c2175c /qtmips_asm | |
parent | c9c26ded68678e26efd316a8f48dd8975dea3048 (diff) | |
download | qtmips-7a684802ddfb9a21a9693ba62029349ab43ce1f1.tar.gz qtmips-7a684802ddfb9a21a9693ba62029349ab43ce1f1.tar.bz2 qtmips-7a684802ddfb9a21a9693ba62029349ab43ce1f1.zip |
Implemented ASCII and ASCIZ operations.
Signed-off-by: Pavel Pisa <pisa@cmp.felk.cvut.cz>
Diffstat (limited to 'qtmips_asm')
-rw-r--r-- | qtmips_asm/simpleasm.cpp | 73 |
1 files changed, 73 insertions, 0 deletions
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, |