Giter VIP home page Giter VIP logo

sap-1's Introduction

SAP-1 Emulator in Python

This repository contains a Python implementation of the Simple As Possible 1 (SAP-1) computer architecture. The SAP-1 is a basic computer architecture designed for educational purposes to understand the fundamental concepts of computer organization and assembly programming.

Features

  • Emulates the SAP-1 architecture with a simple CPU and memory model
  • Supports a subset of SAP-1 instructions, including:
    • LDA: Load value from memory address to accumulator
    • ADD: Add value from memory address to accumulator
    • SUB: Subtract value from memory address from accumulator
    • JNZ: Jump to memory address if accumulator is not zero
    • STA: Store value from accumulator to memory address
    • HLT: Halt the program
  • Assembler to convert assembly instructions to machine code
  • Emulation loop to fetch, decode, and execute instructions
  • Example program to calculate the sum of numbers from 1 to N

Usage

  1. Clone the repository:

    git clone https://github.com/rsinghal757/sap-1.git
    
  2. Run the emulator:

    python sap1_emulator.py
    
  3. Modify the assembly_program in the main() function to create your own SAP-1 programs.

Example Program

The provided example program calculates the sum of numbers from 1 to N, where N is stored in memory location 15. The program uses a loop to add each number to the sum, which is stored in memory location 17.

LDA 15    # Load N into the accumulator
STA 10    # Store N in memory location 10 (loop counter)
LDA 17    # Load the sum into the accumulator
ADD 10    # Add the current loop counter to the sum
STA 17    # Store the updated sum in memory location 17
LDA 10    # Load the loop counter into the accumulator
SUB 16    # Subtract 1 from the loop counter
STA 10    # Store the updated loop counter in memory location 10
JNZ 2     # Jump to the instruction at memory location 2 if the loop counter is not zero
HLT       # Halt the program

Contributing

Contributions are welcome! If you find any issues or have suggestions for improvements, please open an issue or submit a pull request.

License

This project is licensed under the MIT License.

sap-1's People

Contributors

rsinghal757 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.