/** lc3_assemble_one * * Assembles one instruction. */ unsigned short lc3_assemble_one(lc3_state& state, unsigned short address, const std::string& line, int lineno, const LC3AssembleOptions& options) { LC3AssembleContext context; context.line = line; context.lineno = lineno; context.state = &state; context.address = address; context.options = options; unsigned short ret = lc3_assemble_one(state, context); if (context.options.multiple_errors && !context.exceptions.empty()) throw context.exceptions; return ret; }
/** SetValue * * Sets a value at a cell */ void MemoryView::SetValue(int item, int col, const wxString &value) { unsigned short addr = ViewToAddress(item); int data = 0; wxString effvalue = value; std::string strdata; std::string newsym; char *errstr; switch(col) { case MemoryHexadecimal: if (value.StartsWith(_("x")) || value.StartsWith(_("X"))) effvalue = _("0") + value; else if (!(value.StartsWith(_("0x")) && value.StartsWith(_("0X")))) effvalue = _("0x") + value; strdata = effvalue.ToStdString(); data = (int)strtol(strdata.c_str(), &errstr, 16); if (*errstr) return; lc3_mem_write(state, addr, (short)data, true); break; case MemoryDecimal: if (value.StartsWith(_("#"))) effvalue = value.Mid(1); strdata = effvalue.ToStdString(); data = (int)strtol(strdata.c_str(), &errstr, 10); if (*errstr) return; lc3_mem_write(state, addr, (short)data, true); break; case MemoryLabel: strdata = lc3_sym_rev_lookup(state, addr); newsym = value.ToStdString(); if (!strdata.empty()) lc3_sym_delete(state, strdata); data = lc3_sym_lookup(state, newsym); if (data == -1) lc3_sym_add(state, newsym, addr); else wxMessageBox(wxString::Format("ERROR! The symbol %s already exists at address 0x%04x", newsym, data), _("ERROR")); break; case MemoryBinary: if (value.StartsWith(_("0b"))) effvalue = value.Mid(2); strdata = effvalue.ToStdString(); data = (int)strtol(strdata.c_str(), &errstr, 2); if (*errstr) return; lc3_mem_write(state, addr, (short)data, true); break; case MemoryInstruction: try { strdata = effvalue.ToStdString(); if (!strdata.empty()) lc3_mem_write(state, addr, (short)lc3_assemble_one(state, addr, strdata), true); else lc3_mem_write(state, addr, 0, true); } catch (LC3AssembleException e) { effvalue = e.what(); wxMessageBox(wxString::Format("ERROR! %s", effvalue), _("Assemble Error")); } catch (std::vector<LC3AssembleException> e) { effvalue = e[0].what(); wxMessageBox(wxString::Format("ERROR! %s", effvalue), _("Assemble Error")); } break; default: break; } }