Coder Social home page Coder Social logo

lbf38 / mini-mips-project Goto Github PK

View Code? Open in Web Editor NEW
0.0 2.0 1.0 337 KB

Projet Architecture des Ordinateurs @ ENSTA Bretagne - 2A

C 46.45% Makefile 3.25% Python 50.30%
assembler c mips-architecture mips-assembly mips-simulator python school-project

mini-mips-project's Introduction

mini-MIPS Project

GitHub release (latest by date)

README available in the following languages :

English documentation (en_US) French documentation (fr_FR)

Table of contents


Short explanation of this project

This project is an academic project during the second year of study at ENSTA Bretagne (Brest, France).

It aims to reproduce a simple version of the MIPS architecture (therefore the name "mini-MIPS") in order to understand the functioning of a computer and its internal architecture.

It is composed of a virtual machine (VM) and an assembler. The first one is written in C and the second one in Python.

Installation

  1. To install the project, please clone this repository in a Linux environnement. You can use the following command :

    git clone https://github.com/LBF38/mini-MIPS-project.git
  2. Then, you can go to the corresponding folder in your terminal and use the following command to compile the VM :

    make
  3. You can now use the VM and the assembler.

Usage

Assembleur

To launch the assembler, use the format :

./src/assembleur.py [folder/source.txt] [folder/destination.bin]

Note: This command is executed in the project folder, for example under Linux : ~/mini-MIPS-project$

Example :

./src/assembleur.py data/asm.txt bin/asm.bin

If you don't specify the name of the destination file, by default the assembler will write in bin/[source name].bin

Virtual Machine

To launch the VM, use the format :

./bin/vm bin/[source].bin

Example :

./bin/vm bin/asm.bin

Note: You can compile the VM files (which is in C) with the makefile using make

Demonstration

To demonstrate the use of the assembler and the VM, you can find some examples of assembly code in the data/ folder.

This files respect the semantic chosen for the basic instructions of the VM. You can find it in the file instructions.md.

A list of simple examples

Je vais vous présenter les fichiers d'exemples que vous pouvez trouver dans le dossier data/, en vous donnant une courte explication de leur fonctionnement.

In this part, I will present the files that you can find in the data/ folder, giving you a short explanation of their functioning.

  • asm.txt : This file contains an example of assembly code. It is used to demonstrate the use of the assembler. It allows to test the comments, the basic instructions, the labels and the empty lines.
  • affiche12.txt : This file contains an example of assembly code to display 12 by performing a loop of 12 iterations.
  • factorial.txt : This file contains an example of assembly code to display the factorial of a number. The user is asked for a value to calculate and we can thus calculate the associated factorial. We can ask for a value between 0 and 12.

For this program, the limiting factor is the stack pointer which can be too low compared to the value requested by the user. We can see to improve this by calculating a larger stack pointer value depending on the value requested by the user and the maximum available memory.

We are also limited by the representation of numbers. We cannot exceed 2^32-1 (4294967295) because we use a uint32_t to store the numbers.

  • fibonnaci.txt : This file contains an example of assembly code to display the Fibonacci sequence. The code will ask the user for a value and the Fibonacci sequence will be calculated depending on this value.

For this program, the limiting factor is the same as for factorial.txt: the representation of numbers will condition the maximum value available to calculate and display.

  • boucle.txt : This file contains an example of assembly code to launch a loop and display its index.
  • helloworld.txt : This file contains an example of assembly code to display "Hello World!".

Note: helloworld.txt does not work for the moment because the data of type string are not yet recognized or treated by the assembler.

  • instruction_test.txt : This file contains all the instructions available in my asm semantic. It allowed me to test all the functions one by one and to check their functioning, when I had implementation problems.

A better method would have been to make unit tests directly on the assembler. I would implement them if I have the time. (see #10)

Ideas

You will find here some ideas of programs to be made in assembly to test the assembler and the VM. These ideas come from the computer architecture course at ENSTA Bretagne and the ideas of the teachers.

  • Calculate the points of the line $y = ax + b$ from the parameters provided by the user.
  • Matrix calculation, matrix multiplication.
  • Implementation of the Bresenham algorithm to draw a line. (Bresenham algorithm)
  • Syracuse sequence. (Syracuse sequence)

Ressources

Credits

This project was made by Mathis URIEN (@LBF38), student in Design of Digital Sytems at ENSTA Bretagne.

The course and project was given by ENSTA Bretagne's professors.

mini-mips-project's People

Contributors

lbf38 avatar thomas40510 avatar

Stargazers

 avatar

Watchers

 avatar  avatar

Forkers

thomas40510

mini-mips-project's Issues

Assembleur ne gère pas les données fournis via un label

La majorité de l'assembleur est fonctionnelle (pour ne pas dire la totalité). Cependant, avec le code ci-dessous qui est censé afficher "Hello World!" 5 fois, je ne sais pas comment gérer les données.

# print 5 times "Hello, world!"
    add r2 r0 nb_iter      # r2 <= @nb_iter
    load r3 r2 0            # r3 <= mem[r2 + 0]
    add r4 r0 0             # r4 <= 0
loop_for_start:
    slt r5 r4 r3            # r5 <= (r4 < r3) ? 1 : 0
    braz r5 loop_for_end    # if (r5 == 0) {PC <= loop_for_end}
    add r20 r0 my_string   # r20 <= @my_string
    scall 4                 # print string @r20 to stdout
    add r4 r4 1             # r4 <= r4 + 1
    jmp r0 loop_for_start   # PC <= @loop_for_start
loop_for_end:
    stop                    # halt the machine
nb_iter:
    5                       # data: number 5
my_string:
    "Hello, world!\n"       # data: null terminated string

Le nb_iter est bien géré. Seul le my_string n'est pas bien géré.

Ainsi, j'ai identifié deux problèmes que je réunis ici car ils sont intrinsèquement liés :

  • Reconnaître et stocker les données sous forme de string. (comme la partie my_string ci-dessus) => partie assembleur
  • Reconnaître et fournir la string lors du décodage dans la VM. => partie VM.

A fixer :

  • scall 4
  • reconnaissance des data sous forme de string
  • décodage des data sous forme de string
  • stockage au bon endroit dans la mémoire
  • appel via scall 4

Documentation et exemples de codes en assembleur

What needs to be done

Maintenant que tout fonctionne, il faut que je nettoie tous les fichiers et que je les documente.
Utilisation de la documentation doxygen pour les codes en C.
Regarder docstrings pour les codes en python.

Pour les exemples, on peut reprendre les exemples de moodle et les faire pour mon implémentation de l'assembleur et de l'ISS.
Une fois cela fait, on peut rendre le projet sur Moodle avant le 22 décembre 2022.

Liste des points à vérifier avant première version à rendre:

  • Commenter les parties importantes du code
    • Pour l'assembleur
    • Pour la VM
  • Créer des exemples simples et fonctionnels de code en instructions asm
    • factorial
    • print12
    • multiplication matricielle
    • Suite de Syracuse
    • printHelloWorld (à voir car ne gère pas encore les data strings)

Problème de création du dossier bin/ sur une nouvelle configuration

Il faut que je reprenne l'assembleur pour vérifier que la création de tous les dossiers se fait bien lors de l'assemblage du code.
Par exemple, lorsqu'on lance la commande en ne mettant que le premier paramètre (le nom du fichier à compiler), il faut que l'assembleur crée le dossier bin pour accueillir le fichier binaire assemblé.

Problème avec les branchements et les boucles

Après plusieurs essais infructueux, je ne parviens toujours pas à faire des boucles ou à utiliser les branchements pour des fonctions simples en assembleur.

La VM ne semble pas reconnaître les instructions de branchements lors de boucles alors que celle-ci fonctionne individuellement.
Mais en testant chacune des instructions (jmp, braz, branz), elles fonctionnent quand elles sont seules dans leur programme.
Peut-être que cela vient d'un problème de programmation en assembleur ? Je ne sais pas.

Cela peut également venir des opérateurs de comparaison qui fonctionnerait mal.. C'est bizarre.

Refactor code (Assembleur)

Refactor all the Assembleur.py code to have a cleaner architecture and easier way to read files.
This is a work that would help me for the compiler part in next months (see in Semester 4 with the Compiler course)

Documentation Doxygen - générer automatiquement pour deux langages (C et python)

J'aimerais générer une documentation doxygen automatiquement à partir de mes commentaires dans le code.
Pour cela, j'aimerais générer à la fois pour les fichiers python et les fichiers C.

Dans l'idée, j'ai créé deux fichiers de configuration distincts pour chacun des langages. Mais cela ne fonctionne pas. Il faut sûrement que j'ajoute d'autres éléments de configuration ou autres.

A regarder si j'ai le temps, plus tard.

Refactor code (VM)

Same as Assembleur.py, need to refactor code of vm.c to be more readable and easier to grow from.
Moreover, this work will help me in the future to add the compiler part from Semester 4 course on Compiler

Make unit tests for testing each instruction in the Assembleur

With the power of unit testing, we can test every instruction that the Assembleur need to recognize.
It will automate much of the work to verify if all is working.

But, need to be cautious about how the code is written because tests will depend on the function and code architecture.
=> need more time to dig into these details.

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.