Create signal/slot support for informing parser of assembled data at differring base adresses
MODIFY
src/assembler.cpp
src/assembler.cpp
@@ -388,7 +388,7 @@ QByteArray Assembler::assembleInstruction(const QStringList& fields, int row) {
m_error = true;
Q_ASSERT(false);
}
- return 0;
+ return QByteArray();
}
void Assembler::unpackPseudoOp(const QStringList& fields, int& pos) {
@@ -635,10 +635,11 @@ inline QByteArray Assembler::uintToByteArr(uint32_t in) {
void Assembler::restart() {
m_error = false;
+ m_hasData = false;
m_instructionsMap.clear();
m_lineLabelUsageMap.clear();
m_labelPosMap.clear();
- m_outputArray.clear();
+ m_textSegment.clear();
}
namespace {
@@ -650,7 +651,7 @@ inline QStringList splitColon(const QString& string) {
out.removeAll("");
return out;
}
-}
+} // namespace
const QByteArray& Assembler::assembleBinaryFile(const QTextDocument& doc) {
// Called by codeEditor when syntax has been accepted, and the document should be assembled into binary
@@ -702,7 +703,7 @@ const QByteArray& Assembler::assembleBinaryFile(const QTextDocument& doc) {
// Since the keys (line numbers) are sorted, we iterate straight over the map when inserting into the output
// bytearray
for (auto item : m_instructionsMap.toStdMap()) {
- m_outputArray.append(assembleInstruction(item.second, item.first));
+ m_textSegment.append(assembleInstruction(item.second, item.first));
}
- return m_outputArray;
+ return m_textSegment;
}

MODIFY
src/assembler.h
src/assembler.h
@@ -9,8 +9,10 @@ public:
Assembler();
const QByteArray& assembleBinaryFile(const QTextDocument& doc);
bool hasError() { return m_error; }
- const QByteArray& getCurrentOutputArray() { return m_outputArray; }
- void clear() { m_outputArray.clear(); }
+ bool hasData() { return m_hasData; }
+ const QByteArray& getTextSegment() { return m_textSegment; }
+ const QByteArray& getDataSegment() { return m_dataSegment; }
+ void clear() { m_textSegment.clear(); }
private:
uint32_t getRegisterNumber(const QString& reg);
@@ -26,8 +28,10 @@ private:
m_lineLabelUsageMap; // Lines that need to be updated with label values (offsets) after unpacking is finished
QMap<int, QStringList> m_instructionsMap; // Map containing unpacked and offset-modified instruction
- QByteArray m_outputArray;
+ QByteArray m_textSegment;
+ QByteArray m_dataSegment;
bool m_error = false;
+ bool m_hasData = false;
// Assembler functions
QByteArray assembleInstruction(const QStringList& fields, int row);

MODIFY
src/codeeditor.cpp
src/codeeditor.cpp
@@ -59,9 +59,13 @@ void CodeEditor::setupAssembler() {
void CodeEditor::assembleCode() {
if (m_tooltipForLine.isEmpty()) {
// No tooltips available => syntax is accepted
+
const QByteArray& ret = m_assembler->assembleBinaryFile(*document());
if (!m_assembler->hasError()) {
- emit assembledSuccessfully(ret);
+ emit assembledSuccessfully(ret, true, 0x0);
+ if (m_assembler->hasData()) {
+ emit assembledSuccessfully(m_assembler->getDataSegment(), false, DATASTART);
+ }
} else {
QMessageBox err;
err.setText("Error in assembling file.");

MODIFY
src/codeeditor.h
src/codeeditor.h
#include <QScrollBar>
#include <QTimer>
-#include "syntaxhighlighter.h"
#include "assembler.h"
+#include "syntaxhighlighter.h"
#include <set>
@@ -32,14 +32,14 @@ public:
void enableBreakpointArea();
void reset() { m_highlighter->reset(); }
void setTimerEnabled(bool state) { m_timerEnabled = state; }
- const QByteArray& getCurrentOutputArray() { return m_assembler->getCurrentOutputArray(); }
+ const QByteArray& getCurrentOutputArray() { return m_assembler->getTextSegment(); }
void clearOutputArray() {
m_assembler->clear();
m_tooltipForLine.clear();
}
signals:
void readyToTranslate(); // Emitted when syntax has been accepted, and the input text can be translated to
- void assembledSuccessfully(const QByteArray& code);
+ void assembledSuccessfully(const QByteArray& bytearray, bool clearSimulatorMemory, uint32_t baseAddress);
protected:
void resizeEvent(QResizeEvent* event) override;

MODIFY
src/parser.cpp
src/parser.cpp
@@ -52,6 +52,9 @@ void Parser::parseFile() {
void Parser::clear() {
m_disassembledRepr.clear();
m_binaryRepr.clear();
+
+ // Reset the pipeline
+ Pipeline::getPipeline()->reset();
}
const QString& Parser::loadBinaryFile(QString fileName, bool disassembled) {
@@ -71,23 +74,23 @@ const QString& Parser::loadBinaryFile(QString fileName, bool disassembled) {
}
}
-const QString& Parser::loadFromByteArray(QByteArray arr, bool disassembled) {
- // Reset the pipeline
- clear();
- Pipeline::getPipeline()->reset();
+const QString& Parser::loadFromByteArray(QByteArray arr, bool disassembled, uint32_t baseAddress) {
+ // Loads the input arr into the memory of the simulator
+ // Baseaddress is default = 0 (text). Can be changed for inserting into ie. data memory
+
QString output = "";
MainMemory* memPtr = Pipeline::getPipeline()->getMemoryPtr();
auto length = arr.length();
QDataStream in(&arr, QIODevice::ReadOnly);
char buffer[4];
- int pc = 0;
+ int byteIndex = baseAddress;
for (int i = 0; i < length; i += 4) {
in.readRawData(buffer, 4);
QString binaryRepString;
for (int j = 0; j < 4; j++) {
binaryRepString.prepend(QString().setNum((uint8_t)buffer[j], 2).rightJustified(8, '0'));
- memPtr->write(pc, buffer[j], 1);
- pc++;
+ memPtr->write(byteIndex, buffer[j], 1);
+ byteIndex++;
}
m_binaryRepr.append(binaryRepString).append('\n');
uint32_t instr =
@@ -97,6 +100,7 @@ const QString& Parser::loadFromByteArray(QByteArray arr, bool disassembled) {
}
// Update the pipeline
Pipeline::getPipeline()->update();
+ if (baseAddress == 0)
m_disassembledRepr = output;
if (disassembled) {

MODIFY
src/parser.h
src/parser.h
@@ -37,7 +37,7 @@ public:
QString getInstructionString(uint32_t address) const;
- const QString& loadFromByteArray(QByteArray arr, bool disassembled = true);
+ const QString& loadFromByteArray(QByteArray arr, bool disassembled = true, uint32_t baseAddress = 0x0);
const QString& loadBinaryFile(QString fileName, bool disassembled = true);
const QString& getBinaryRepr() { return m_binaryRepr; }
const QString& getDisassembledRepr() { return m_disassembledRepr; }

MODIFY
src/programfiletab.cpp
src/programfiletab.cpp
@@ -62,8 +62,10 @@ void ProgramfileTab::setDisassemblerText() {
m_ui->binaryedit->setPlainText(text);
}
-void ProgramfileTab::assemblingComplete(const QByteArray& arr) {
- Parser::getParser()->loadFromByteArray(arr, m_ui->disassembledViewButton->isChecked());
+void ProgramfileTab::assemblingComplete(const QByteArray& arr, bool clear, uint32_t baseAddress) {
+ if (clear)
+ Parser::getParser()->clear();
+ Parser::getParser()->loadFromByteArray(arr, m_ui->disassembledViewButton->isChecked(), baseAddress);
setDisassemblerText();
emit updateSimulator();
}

MODIFY
src/programfiletab.h
src/programfiletab.h
@@ -32,7 +32,7 @@ private slots:
void on_pushButton_clicked();
void on_assemblyfile_toggled(bool checked);
- void assemblingComplete(const QByteArray& binaryCode);
+ void assemblingComplete(const QByteArray& binaryCode, bool clear = true, uint32_t baseAddress = 0x0);
void on_disassembledViewButton_toggled(bool checked);

Create signal/slot support for informing parser of assembled data at differring base adresses