Coder Social home page Coder Social logo

co_project's Introduction

CO Project

This is the github repository of our Computer Organisation project.

input.txt

This file contains the input code.

machine_code.txt

This file contains the output code.

assembler.py

This is the main program and it contains the code for the assembler.

Sections of code explained :-

Defining Variables: This section defines various variables used in the assembler. These variables keep track of the state of the assembler, such as the current instruction type, error flags, counters, and flags for different conditions.

We define dictionaries to store the mappings between instructions and their binary representations.

Decimal to Binary Conversion: The decimaltobinary function converts decimal values to binary with seven digits. It uses recursion.

Seven-bit Memory and Immediate Variables: The seven_bit function is for checking if the binary representation exceeds seven bits. An overflow error is flagged in case it does.

Assembler main: The assembler function is the main part of the program. It takes an instruction as input and processes it to generate the corresponding machine code.

Detecting the type of an instruction: This checks the first word and the length of the instruction to determine the instruction type.It sets the appropriate variables and flags to handle the instruction later.

Reading var declaration in assembly: defines variable declaration in assembly code by looking for "var" in the beginning of the string.The variables dictionary is updated accordingly.

Label definition: label defining works by looking for ":" at the end of instruction. The labels dictionary is updated with the label's binary representation.

Converting Registers and Memory Addresses to Machine Code: This section converts register names and memory addresses to corresponding binary representations. It also handles the FLAGS register and immediate values.

Storing Machine Code to Write in the File: The machine code is stored in write_data(a list), which is later used to write the machine code into the output file.

Label handling: This is done by giving each line a seven bit binary address counting up. The binary representation of the label is appended to the machine code of the instruction that requires the label.

Variable address is a 7 bit number counting up for each variable.

Label Run: After processing all instructions once, the label_run flag is set to true to indicate that the instructions are to be processed again taking labels into account.

Checking Halt Instruction: For checking if the assembly code ends with 'halt'. If not, an error is flagged.

Writing the Machine Code to a File: If no errors were encountered during the assembly process, the machine code is written to the output file. Otherwise, the first error encountered is written to the file.

Team Members : Vaibhav Chopra - 2022552, Tarush Garg - 2022537, Tejus Madan - 2022540, Paarth Goyal - 2022343

co_project's People

Contributors

firebred123 avatar pluto-tofu avatar tejusmadan avatar vaibhav-chopra-gt avatar

Stargazers

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