bool Assembler::ParseLine(string& line, int linecount, Assembly& assembly, LabelVector& labels) { string op; int i = NextWord(line, op); // skip commented and empty lines if(i == -1 || op == "//" || op == ";") return true; // this is a a very slow way of doing things, but then this code will only // be used during development and for debugging OpDesc *opcode; int codecount = sizeof(opcodes)/sizeof(OpDesc); int j = 0; for(; j < codecount; j ++) { if(stricmp(opcodes[j].name, op.c_str()) == 0) { opcode = &opcodes[j]; break; } } // is this a label? if(j == codecount) { size_t k = op.length() - 1; if(op.find_first_of(":") == k) { string name = op.substr(0, k); labels.at(AddLabel(name, labels)).pos = assembly.curpos; return true; } else return false; } else { assembly.WriteDword(opcode->code); string param; i = NextWord(line, param, i); if(IsJumpOp(opcode->code)) { // write the label index, we'll later replace this with the code position assembly.WriteDword(AddLabel(param, labels)); } else { if(i == -1) { assembly.WriteDword(0); if(opcode->paramcount > 0) return false; // if we need more params, bail } else assembly.WriteDword(StringToOperand(param, opcode)); } } return true; }