remove spurious 4 + in blob offset calculation

This commit is contained in:
Zack Buhman 2022-04-16 12:24:35 -07:00
parent 210a8d1b06
commit 0dda2ad13f
3 changed files with 17 additions and 4 deletions

15
main.cc
View File

@ -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<assembler::reference_t>(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;

View File

@ -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<ssize_t> {
@ -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) {

View File

@ -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);
}