JSPM

  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 58
  • Score
    100M100P100Q77929F
  • License MIT

MIPS Simulator npm package

Package Exports

    This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (mips-simulator-js) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

    Readme

    MIPS Simulator

    GitHub Workflow Status Weekly Downloads version

    You can use Node.js MIPS Simulator with npm

    Git Repository

    Coverage Status

    Contribution

    We have completed building CI, and test automation is also ready.

    Always opening to join this project for developing this library.

    ❗️ISSUE

    Pull Request

    support

    JavaScript TypeScript

    Demo GUI

    Not Yet


    Introduction

    This open source provides functions to implement MIPS simulation in node.js environment.

    Currently, we support a function to convert an assembly file to a binary file. In the future, we plan to add the function of simulating with actual assembly files.


    Install

    npm install --save mips-simulator-js

    Format

    makeInput

    export function makeInput(inputFolderName: string, inputFileName : string) {
        return assemblyInput : string[]
    }

    makeObjectFile

    export function makeObjectFile(
      outputFolderPath: string,
      outputFileName: string,
      content: string[],
    ) {
      return;
      // make .o file to outputFolderPath
    }

    assemble

    export const assemble = (assemblyFile : string[]) => {
      ...
      return output : string[]
    };

    Usage

    Assembly Language → Binary Instruction

    // import functions
    
    /*
     *   if the inputFilePath is '/Users/user/simulator/sample_input/sample/example1.s',
     *   currDirectory : '/Users/user/simulator'
     *   inputFolderPath : 'sample_input/sample'
     *   inputFileName: 'example1.s'
     */
    const inputFolderName = 'sample_input/sample';
    const inputFileName = 'example1.s';
    /*
     *   if the outputFilePath is '/Users/user/simulator/sample_input/sample/example1.s',
     *   currDirectory : '/Users/user/simulator'
     *   outputFolderPath : 'sample_input/sample'
     *   outputFileName: 'example1.o'
     *   content : ['01010', '01010']
     */
    const outputFolderPath = 'sample_input/sample';
    const outputFileName = 'example1.o';
    
    const assemblyFile = makeInput(inputFolderName, inputFileName);
    const binary = assemble(assemblyFile);
    
    makeObjectFile(outputFolderPath, outputFileName, binary);

    Input/Output

    Usage for React/Next

    Problem

    If you use this npm package in your react or next project, problems will occur in the 'fs', 'path', and 'process' parts that load files.

    reactError

    This problem is caused by the webpack version. For details, refer to the webpack official documentation.

    Solution

    The solution is to change the webpack configuration to false as shown below and import the file using fetch.

    1. Change webpack config and package settings
    // node_modules/react-scripts/config/webpack.config.json
    module.exports = function (webpackEnv) {
      // ...
      return {
        // ...
        resolve: {
          // ...
          // Add This!👇
          fallback: {
            "fs": false,
            "path": false,
            "process": false,
          },
          // ...
        }
      }
    }
    // package.json
    {
        // ...
      "dependencies": {},
      "devDependencies": {},
    
      // Add This👇️
      "browser": {
        "fs": false,
        "os": false,
        "path": false
      }
    }
    1. Creating a file calling function using fetch (This function is a replacement for 'makeInput' provided by the library for use in React / Next.)
    const fetchFile = async (filePath: string) => {
      await fetch(filePath)
        .then(response => response.text())
        .then(text => {
          // Create a function to use and put it here!
        });
    };
    
    // Example
    
    const [fileContent, setFileContent] = useState('');
    const [binaryInstruction, setBinaryInstruction] = useState<string[] | null>(
        null
      );
    
    useEffect(() => {
      const fetchFile = async (filePath: string) => {
        await fetch(filePath)
          .then(response => response.text())
          .then(text => {
            setFileContent(text.split('\n'));
          });
      };
      const filePath = `sample_input/example01.s`;
      fetchFile(filePath);
    }, [setFileContent]);
    
    useEffect(() => {
      if (fileContent)
        setBinaryInstruction(assemble(fileContent).split("\n"));
    }, [fileContent]);
    

    ⚠️ Caution

    In the browser, unlike in the local environment, only files or documents in the public path can be used, and the default path is automatically designated as public. Therefore, the assembly file to be converted into an object file using assembler must be stored in the public folder.


    Supported Instruction

    you can check MIPS Reference

    In this library, we support below instructions

    Instruction Format opcode funct
    SLL R 000000 000000
    SRL R 000000 000010
    JR R 000000 001000
    ADD R 000000 100000
    ADDU R 000000 100001
    AND R 000000 100100
    NOR R 000000 100111
    OR R 000000 100101
    SLT R 000000 101010
    SLTU R 000000 101011
    SUB R 000000 100010
    SUBU R 000000 100011
    LUI I 001111 null
    BEQ I 000100 null
    BNE I 000101 null
    LW I 100011 null
    LHU I 100101 null
    SW I 101011 null
    SH I 101001 null
    ADDI I 001000 null
    ADDIU I 001001 null
    ANDI I 001100 null
    ORI I 001101 null
    SLTI I 001010 null
    SLTIU I 001011 null
    J J 000010 null
    JAL J 000011 null

    pseudo Instruction

    la (load address)

    la $2, VAR1

    • VAR1 is a label in the data section. It should be converted to lui and ori instructions.

    • lui $register, upper 16bit address ori $register, lower 16bit address If the lower 16bit address is 0x0000, the ori instruction is useless.

      • Case1) load address is 0x1000 0000


        lui $2, 0x1000
      • Case2) load address is 0x1000 0004


        lui $2, 0x1000
        ori $2, $2, 0x0004

    move

    move $1, $2

    It should be converted to add instruction with $0 as a target register(rt).


    Contribution

    If you want to contribute to mips-simulator-js, please come in Git Repository and clone!

    We have completed building CI, and test automation is also ready.

    We are using testing library with jest

    Always opening to join this project for developing this library.

    ❗️ISSUE

    Pull Request

    required environment (global)

    $ npm install typescript -g

    License

    Licensed under the MIT License, Copyright © 2023-present MIPS-Simulator-UNIST