Giter Club home page Giter Club logo

simulator's Introduction

Intermediate Code Generator & Simulator

This repository contains an intermediate code generator and simulator for a specific Instruction Set Architecture (ISA). The code generator takes a specific input format and generates intermediate code, while the simulator executes the generated code.

๐Ÿ“ Intermediate Code Generator

The intermediate code generator is implemented in Python. It takes a specific input format from the standard input (stdin) and generates intermediate code as output. The generated code can be used as input for the simulator.

โŒจ๏ธ Input Format

The input format for the code generator follows specific rules:

  • Instructions should be space-separated.
  • The last element of every line should be a newline character '\n'.
  • The program supports various types of instructions, including arithmetic instructions, register-shift instructions, move instructions, load instructions, store instructions, division instructions, not instructions, comparison instructions, jump instructions, halt instructions, variable definitions, and label definitions.

๐Ÿš€ Usage

  1. Prepare a text file containing the input instructions in the specified format.
  2. Run the code generator program in the terminal or command prompt:
    • python code_generator.py < input.txt
      Replace code_generator.py with the actual filename of the program, and input.txt with the filename of your input file.
  3. The program will generate the intermediate code as output.

๐Ÿ’ป Simulator

The simulator is implemented as a separate component. It takes a binary file (in the same format as generated by the code generator) as input and executes the code. The simulator loads the binary into system memory, starts executing the code from address 0, and continues until the "hlt" instruction is reached.

๐Ÿงฉ Components

The simulator consists of the following distinct components:

  1. Memory (MEM): The memory component stores 512 bytes of data. It takes an 8-bit address and returns a 16-bit value as the data.

  2. Program Counter (PC): The program counter is an 8-bit register that points to the current instruction.

  3. Register File (RF): The register file component takes the register name (R0, R1, ..., R6, or FLAGS) and returns the value stored in that register.

  4. Execution Engine (EE): The execution engine component takes the address of the instruction from the program counter, retrieves the instruction from memory, and executes it by updating the register file and program counter.

๐Ÿš€ Usage

  1. Prepare a binary file using the intermediate code generated by the code generator.
  2. Run the simulator program in the terminal or command prompt:
  • python simulator.py < binary_file.bin
    Replace simulator.py with the actual filename of the simulator program, and binary_file.bin with the filename of your binary file.
  1. The simulator will load the binary into memory and start executing the code.
  2. After each instruction, the simulator will output one line containing the program counter and the values of the registers (R0, R1, ..., R6, and FLAGS).
  3. Once the program is halted, the simulator will print the memory dump of the entire memory, consisting of 256 lines with 16-bit values.

๐ŸŒŸ Example

To understand the input format, code generation, and simulation, you can refer to the provided example files (input.txt for the code generator and binary_file.bin for the simulator).

Feel free to explore and modify the code generator and simulator according to your requirements. If you encounter any issues or have suggestions for improvement, please don't hesitate to open an issue or submit a pull request.

simulator's People

Contributors

swati-sharma14 avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.