|
This post was updated on .
I initially decided on Python but part way through that implementation I gave up on it due to unfamiliarity with the language. Felt more comfortable in C/C++ because that's my coding background.
I'm about 1/8 of the way through Pong.asm conversion using the supplied Assembler.sh and everything is comparing fine, just fine. I used quite a few of the standard libraries to get it done and only used one class for it which handles everything, basically it's just a secondary main with an excuse to have global variables :) Not at all an OO approach.
Here is the main():
int main(int argc, char** argv)
{
if(argc > 1)
{
for(int i = 1; i < argc; ++i)
Parser tmp(argv[i]);
}
else
{
std::cout << "Usage:\tAssembler filename1.asm filename2.asm <...> filenameN.asm" << std::endl;
return 0;
}
return 0;
}
The declaration of Parser.h:
class Parser
{
public:
Parser(char*);
~Parser();
private:
bool hasMoreCommands();
void advance_command();
void init_variables();
const char* out_rename(char*);
std::ifstream in_asm;
std::ofstream out_hack;
bool second_pass;
std::string cur_command;
unsigned int com_pos, var_inc;
std::multimap<std::string, unsigned int> mmap_com_pos;
std::multimap<std::string, std::bitset<16> > mmap_constants, mmap_jump,
mmap_comp, mmap_dest;
std::map<std::string, unsigned int> map_var_loc;
std::bitset<16> c_comp, to_write;
};
A whole lot of optimisation could be done, but I'll save it for a rainier day than this. I'm just pleased it was successful. Came in at about 240-260 lines of code and 10 includes from the standard libraries.
Send me an E-Mail and I'll send you the full code if you'd be so kind and send me yours as well.
EDIT: D'OH! Well, I did the fast translation and hit a snag on the symbol "@ponggame.0" which translated in my code to A-Instruction 0x0000. The hunt is on for this bug :)
EDIT2: All is well. I had constructed an 'if' on my second pass that would store a variable name on first encounter (when it wasn't a L-command) but would not send it to be written. Easy enough to miss easy enough to fix. Now fast compare works flawlessly.
|