assembling first version
This commit is contained in:
parent
9e9039af05
commit
d3e08abd30
7 changed files with 896 additions and 1 deletions
|
|
@ -3,6 +3,8 @@
|
|||
|
||||
#include <vector>
|
||||
#include <memory>
|
||||
#include <unordered_map>
|
||||
#include <cstdint>
|
||||
|
||||
#include "node.h"
|
||||
|
||||
|
|
@ -17,8 +19,42 @@ public:
|
|||
|
||||
const string toString() const;
|
||||
|
||||
// Two-pass assembler methods
|
||||
void assemble();
|
||||
std::vector<uint8_t> emitCode();
|
||||
std::string emitText();
|
||||
std::string dumpSymbols() const;
|
||||
std::string dumpCode() const;
|
||||
|
||||
private:
|
||||
std::vector<std::shared_ptr<Node>> _lines;
|
||||
|
||||
// Assembler state
|
||||
std::unordered_map<std::string, int> _symbolTable;
|
||||
std::vector<int> _locationCounters; // Location counter per line
|
||||
int _startAddress = 0;
|
||||
int _programLength = 0;
|
||||
std::string _programName;
|
||||
int _baseRegister = -1; // -1 means not set
|
||||
|
||||
// Pass 1: build symbol table and assign addresses
|
||||
void firstPass();
|
||||
|
||||
// Pass 2: generate code
|
||||
void secondPass();
|
||||
|
||||
// Helper methods
|
||||
int getInstructionLength(const std::shared_ptr<Node>& node, int locationCounter) const;
|
||||
std::vector<uint8_t> generateInstruction(const InstructionNode* inst, int address);
|
||||
std::vector<uint8_t> generateData(const DataNode* data);
|
||||
|
||||
// Addressing mode selection
|
||||
struct AddressingResult {
|
||||
int nixbpe; // ni, x, b, p, e bits
|
||||
int displacement; // 12-bit or 20-bit
|
||||
bool success;
|
||||
};
|
||||
AddressingResult selectAddressingMode(int targetAddress, int pc, bool indexed, bool immediate, bool indirect, bool extended) const;
|
||||
};
|
||||
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue