Implement ".zero" assembler directive for array allocation
MODIFY
src/assembler.cpp
src/assembler.cpp
@@ -610,6 +610,14 @@ void Assembler::assembleWords(const QStringList& fields, QByteArray& byteArray,
}
}
+// Allocates $size bytes in the static data segment
+void Assembler::assembleZeroArray(QByteArray& byteArray, size_t size){
+ Q_ASSERT(size >= 1);
+ for(int i = 0; i < size; i++){
+ byteArray.append(static_cast<char>(0x0));
+ }
+}
+
void Assembler::assembleAssemblerDirective(const QStringList& fields) {
QByteArray byteArray;
if (fields[0] == QString(".string") || fields[0] == QString(".asciz")) {
@@ -622,6 +630,8 @@ void Assembler::assembleAssemblerDirective(const QStringList& fields) {
byteArray = string.toUtf8();
} else if (DataAssemblerDirectives.contains(fields[0])) {
assembleWords(fields, byteArray, DataAssemblerSizes.value(fields[0]));
+ } else if (fields[0] == QString(".zero")){
+ assembleZeroArray(byteArray, static_cast<size_t>(fields[1].toInt()));
} else if (fields[0] == QString(".data")) {
// Following instructions will be assembled into the data segment
m_inDataSegment = true;

MODIFY
src/assembler.h
src/assembler.h
@@ -20,6 +20,7 @@ private:
void unpackOp(const QStringList& fields, int& pos);
void assembleAssemblerDirective(const QStringList& fields);
void assembleWords(const QStringList& fields, QByteArray& byteArr, size_t size);
+ void assembleZeroArray(QByteArray& byteArray, size_t size);
void restart();
int getImmediate(QString string, bool& canConvert);
QByteArray uintToByteArr(uint32_t);

MODIFY
src/syntaxhighlighter.cpp
src/syntaxhighlighter.cpp
@@ -563,6 +563,15 @@ void SyntaxHighlighter::createSyntaxRules() {
m_syntaxRules.insert(rule.instr, QList<SyntaxRule>() << rule);
rule.instr = ".word";
m_syntaxRules.insert(rule.instr, QList<SyntaxRule>() << rule);
+ rule.hasListField = false;
+
+ // Emit zero's (array allocation on static data segment)
+ types.clear();
+ types << FieldType(Type::Immediate, 1, 0xFFFF);
+ rule.fields = 2;
+ rule.inputs = types;
+ rule.instr = ".zero";
+ m_syntaxRules.insert(rule.instr, QList<SyntaxRule>() << rule);
// .string & .asciz
types.clear();

Implement ".zero" assembler directive for array allocation #14