diff --git a/main.cc b/main.cc index 12d6f10..045c622 100644 --- a/main.cc +++ b/main.cc @@ -27,6 +27,12 @@ void serialize_program(const assembler::program_t& program, const assembler::sym return; } + /* + std::cerr << tostring::op().find(ins.op)->second << ' ' + << tostring::mode().find(ins.mode)->second << ' ' + << std::hex << (int)opcode_it->second << '\n'; + */ + buf[0] = opcode_it->second; auto am_it = addressing_mode().find(ins.mode); @@ -37,7 +43,7 @@ void serialize_program(const assembler::program_t& program, const assembler::sym assembler::reference_t ref = std::get(ins.value); auto sym_it = symbol_table.find(ref.symbol); if (sym_it == symbol_table.end()) { - std::cerr << "get_value: " << ref.symbol << '\n'; + std::cerr << "get_value: `" << std::dec << ref.symbol << "` not found\n"; assert(false); } auto ref_location = sym_it->second; @@ -142,7 +148,12 @@ int main(int argc, char * argv[]) } } - ok = symbol::resolve(0xc000, program, symbol_table); + //auto link_address = 0xc000; + auto link_address = 0x0200; + + std::cerr << "link address: " << std::hex << link_address << '\n'; + + ok = symbol::resolve(link_address, program, symbol_table); if (!ok) return -1; diff --git a/parser.cc b/parser.cc index 2acb3f9..636bd7b 100644 --- a/parser.cc +++ b/parser.cc @@ -144,6 +144,8 @@ bool parse(std::string_view buf, assembler::program_t& program, assembler::symbo continue; } + if (row != current_instruction.row) + std::cerr << row << ' ' << current_instruction.row; assert(row == current_instruction.row); auto parse_integer = [](std::string_view s, int base) -> std::optional { @@ -205,7 +207,7 @@ bool parse(std::string_view buf, assembler::program_t& program, assembler::symbo //std::cerr << "value hex literal `" << *literal << "`\n"; break; } - case 'i': + case '^': { literal = parse_integer(s.substr(1, s.length() - 1), 10); if (literal == std::nullopt) { diff --git a/symbol.cc b/symbol.cc index 2626ed8..82192ee 100644 --- a/symbol.cc +++ b/symbol.cc @@ -51,7 +51,7 @@ bool resolve(size_t link_location, assembler::program_t& program, assembler::sym std::cerr << "duplicate blob symbol\n"; return false; } - offset += 4 + blob.buf->size(); + offset += blob.buf->size(); } else { assert(false); }