2020-08-22 23:52:20 +05:30
2020-08-22 23:52:20 +05:30
2020-08-22 23:52:20 +05:30
2020-08-22 23:36:54 +05:30
2020-08-21 19:39:23 +05:30
2020-08-15 13:34:58 +05:30
2020-08-21 19:07:43 +05:30
2020-08-21 19:39:38 +05:30

The-VM-to-HACK-Translator

Translates Virtual Machine Language into HACK Assembly language.

Important: If you are taking this course then I suggest you to try to write the assembler yourself first, it is not very easy and not very tough too. At least not impossible, because I did it 😘

Get Started with the project

  1. Directory Structure
        .
        |_include      # Contains headers
        |_src          # Contains Source Code and Main
        |_Test-Files   # Example HACK VM Files
    
  2. Clone this repo
        git clone https://github.com/avinal/The-VM-to-HACK-Translator.git
    
  3. Build and run, provide only HACK VM Language file. Don't confuse with .vm extesion.
        cd The-VM-to-HACK-Translator
        make
        ./VMTranslator file.vm
    
  4. Start over after modification
        make clean
    

Tips

In case you want to modify this project, you can use Boost C++ Libraries, they can simplify many tasks needed by this project.

Some Words

This was a nice project and taugh me many things. Given below are some miraculous code snippets that proved to be really useful and are well researched. Hope you will find them useful.

  1. Trim spaces, comments, carrige returns, newline, tab and verticle tabs:
        inline std::string trim(std::string str)
        {
            if (str.find('/') != std::string::npos) // comments
            {
                str.erase(str.find('/'));
            }
            str.erase(0, str.find_first_not_of(" \r\t\v\n")); //prefixing
            str.erase(str.find_last_not_of(" \r\t\v\n") + 1); //surfixing}
            return str;
        }
    
  2. Tokenize a string using C++ with respect to a delimiter, space by defalt (string split):
        #include <sstream>
        #include <vector>
        std::vector<std::string> split(std::string str, char delimiter = ' ')
        {
            std::vector<std::string> tokens;
            std::stringstream tokenizer(str);
            std::string intermediate;
            while (std::getline(tokenizer, intermediate, delimiter))
            {
                tokens.push_back(intermediate);
            }
            return tokens;
        }
    
  3. Fascinating Using Lambdas with Map to implement a function or function pointers. See here
Description
No description provided
Readme MIT 61 KiB
Languages
C++ 77.3%
Scilab 20.3%
Makefile 2.4%