Skip to content

Bauero/Assembly_Interpreter

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

For English πŸ‡¬πŸ‡§ scroll down or click here

O projekcie

PomysΕ‚

Ten projekt jest mojΔ… pracΔ… inΕΌynierskΔ… dotyczΔ…cΔ… napisanego w Pythonie interpretera kodu Asembly 16bit w wersji NASM. Zadaniem programu jest wspomaganie uΕΌytkownika w nauce programowania w niskopoziomowym jezyku, Asembly poprzez dostarczenie mu narzΔ™dzi napisanych w jezyku wysokopoziomowym umoΕΌlilwiajΔ…ce analizΔ™ kodu z poziomu GUI i podejrzenie rezultatΓ³w w trakcie pracy programu.

GΕ‚Γ³wne zaΕ‚oΕΌenia

  • MoΕΌliwoΕ›Δ‡ interpretacij poleceΕ„ z gotowego pliku
  • MoΕΌliwoΕ›Δ‡ uruchomienia programu w trybie interaktywny
  • Podstawowy interfejs I/O przez symulacjΔ™ namiastki terminala
  • MoΕΌliwoΕ›Δ‡ modyfikacji wartoΕ›ci stanu symulowanych komponentΓ³w w trybie interaktywnym
  • MoΕΌliwoΕ›Δ‡ powrotu do stanu sprzed wykonania polecenia
  • MoΕΌliwoΕ›Δ‡ automatycznego wykonywania kolejncyh polceΕ„
  • Podstawowe wykrywanie bΕ‚Δ™dΓ³w i wyΕ›wietlanie potencjalnych ΕΊrΓ³deΕ‚ problemu przy raportowaniu

Przygotowanie do uΕΌycia

Przygotowanie wstΔ™pne

Aby skorzystać z programu należy zainstalować wersję interpretera Python 3.10 lub wyższą (projekt testowany był na wersji Python 3.11).

Jak sprawdzić, czy poprawnie zainstalowaliśmy środowisko?

Aby upewniΔ‡ siΔ™, ΕΌe Python zostaΕ‚ poprawnie zainstalowany, wykonaj nastΔ™pujΔ…ce kroki w terminalu (cmd, PowerShell, Terminal, Bash – w zaleΕΌnoΕ›ci od systemu):

  1. OtwΓ³rz terminal.
  2. Wpisz jednΔ… z poniΕΌszych komend:
python –version

lub

python3 -version

Poprawna instalacja powinna zwrócić numer wersji, np. Python 3.11.8.

JeΕ›li komenda nie zostanie rozpoznana, upewnij siΔ™, ΕΌe:

  • Python zostaΕ‚ zainstalowany i dodany do zmiennej Ε›rodowiskowej PATH,
  • na niektΓ³rych systemach (np. macOS/Linux) domyΕ›lnie moΕΌe byΔ‡ wymagane uΕΌycie python3 zamiast python.

Dodatkowo możesz uruchomić interpreter interaktywny:

python

lub

python3

Po uruchomieniu powinieneś zobaczyć coś w rodzaju:

Python 3.11.8 (default, …)

Aby wyjΕ›Δ‡ z trybu interaktywnego, wpisz exit() lub naciΕ›nij Ctrl + Z (Windows) lub Ctrl + D (Linux/macOS).

πŸ“š Oficjalna dokumentacja instalacji Pythona:
https://docs.python.org/3/using/index.html


Utworzenie Ε›rodowiska wirtualnego i instalacja bibliotek

Po zainstalowaniu interpretera Python i pobraniu projektu, należy stworzyć środowisko wirtualne dla uruchomienia projektu. Więcej informacji można znaleźć na stronie dokumentacji - dla naszego projektu, sprowadzać się będzie to do uruchomienia poleceń w terminalu uruchomionego z poziomu katalogu z repozytorium:

Dla systemΓ³w Linux i MacOS

python3.11 -m pip install venv
python3.11 -m venv my-venv-folder
source my-venv-folder/bin/activate
python3.11 -m pip install -r requirements.txt

Dla systemu Windows

python -m pip install venv
python -m venv my-venv-folder
my-venv-folder\Scripts\activate
python -m pip install -r requirements.txt

Uruchamienie i uΕΌycie programu

Uruchomienie i uΕΌycie programu (po poprawnej instalacji bibliotek i uruchomieniu Ε›rodowiska wirtualnego) sprowadza siΔ™ do uruchomienia programu poleceniem (zakΕ‚adajΔ…c iΕΌ jesteΕ›my w katalogu projektu):

python3.11 main.py

Po uruchomieniu, powinniśmy zobaczyć menu główne:

Welcome Screen GUI

Tryby Pracy

Analizuj plik

W tym trybie zakładamy iż mamy plik, który normalnie kompiluje się, ale nie działa tak jak byśmy oczekiwali. Jeśli spróbujemy uruchomić plik, który zawiera błędy składniowe, zostanie wyświetlony komunikat o błędzie i pojawi się opcja uruchoimenia pliku w trybie interaktywnym.

Poprawne wczytanie pliku, powinno zakończyć się ruchomieniem interpretera z podglądem kodu:

Welcome Screen GUI

Aby rozpocząć pracę należy skorzystać z przycisku Uruchom program:

Welcome Screen GUI

Sekcje programu

  • Rejestry i Flagi - wskazuje wewnΔ™trzy stan symulowanego ukΕ‚adu, pozwalajΔ…c zrozumieΔ‡ podstawΔ™ wykonywanych operacji
  • Kod - podglΔ…d pliku / interetowalnego polecenia, wraz z zaznaczonΔ… liniΔ…, ktΓ³ra zostanie wykonana wciΕ›niΔ™ciem przycisku Wykonaj instrukcjΔ™
  • Segment - pokazuje stan stosu procesora (dla uproszczenia, stos nie zawiera binarnej reprezentacji wykonywanego programu !)
  • Zmienne - ta sekcja pozwala w Ε‚atwy sposΓ³b podejrzeΔ‡ wycinki stosu, w ktΓ³rych uΕΌytkowni zadeklarowaΕ‚ zmienne
  • Terminal - ta sekcja pozwala na wykonywanie podstawowej komunikacji programu z uΕΌytkownikiem przez kilka wybranych poleceΕ„

Egzekucja poleceΕ„

Manualnie

Za pomocΔ… przyciskΓ³w Wykonaj instrukcjΔ™ oraz PowrΓ³t do poprzedniej linii uΕΌytkownik zleca wykonanie nastΔ™pnego polecenia, lub przywrΓ³ceie stanu ukΕ‚adu do momentu sprzed wykonania poprzedniego rozaku.

Praca w trybie auto

Zaznaczenie tego polecenia spowoduje automatyczneg przechodzenie przez kolejne polecenia (symulowanie naciskania przez uΕΌytkownika przycisku Wykonaj instrukcjΔ™) w wybranych odstΔ™pach czasu oznaczonych jako OpΓ³ΕΊnienie.

Schemat pracy

Po załadowaniu i wstępnym sprawdzeniu pliku, możliwe jest wykonywanie kolejnych polceń a także powrót do stanu sprzed egzekucji polcecenia. Możliwy jest podgląd stanu stosu i rejestrów, co umożliwa prześledzenie zmian i porównanie działania z przewidywanym sposobem wykonania programu. Po zakończeniu programu, konieczne jest ponowne uruchomienie by załadować ponownie kod (np. po wprowadzeniu zmian).

Tryb interaktywny

Podczas uruchamiania trybu interakywnego zostajemy powitani przez puste okno, gdzie należy wprowadzić kod, który chcemy zasymulować (wyjątkiem jest otworzenie pliku, którego nie udało się uruchomić w trybie Analizy - zawartość pliku jest wtedy wczytana automatycznie):

Welcome Screen GUI

Analiza kodu, odbywa siΔ™ tak samo jak w trybie analizy, z wyjΔ…tkiem dwΓ³ch kwestii:

  1. MoΕΌliwa jest zmiana wartoΕ›ci rejestru i stosu bezpoΕ›rednio w trakcie pracy programu
  2. Po zatrzymaniu egzekucji, moΕΌliwe jest dokonywanie zmian w kodzie programu (spowoduje to rozpoczΔ™cie wykonywnaia caΕ‚ego programu od poczΔ…tku)

ObsΕ‚ugiwane polecenia i ograniczenia

Z uwagi na rozlegΕ‚oΕ›Δ‡ tematu jakim jest interpretacja poleceΕ„ asemblerowych, wprowadzone zostaΕ‚y pewne ograniczenia natury technicznej i logistycznej do programu ! Oznacza to ΕΌe nie kaΕΌdy program, napisany w Asemblerze jest moΕΌliwy do uruchomienia i interpretacji !

W skrΓ³cie

OgΓ³lna lista obsΕ‚ugiwanych poleceΕ„ widoczna jest w sekcji UkΕ‚ad plikΓ³w programu, w folderze Extras/Instructions and descriptions/. KaΕΌde obsΕ‚ugiwane polcenie, zapisane jest jako oddzielny plik .md, z nazwΔ… bΔ™dΔ…cΔ… obsΕ‚ugiwanym poleceniem.

SzczegΓ³Ε‚owo

Wszystkie szczegΓ³Ε‚y nt. projektu, ograniczeΕ„, implementacji i filozofii pracy programu moΕΌna znaleΕΊΔ‡ w mojej pracy inΕΌynierskiej:


About

General Idea

This project is my engineering thesis which topic is an Assembly 16bit interpreter written in Python language. The goal is to provide user with help in learning low-level language like Assembly by giving tool for analysis and execution of code in high-level language with simple GUI.

Key features

  • Ability to execute assembly file
  • Ability to run program in interactive mode
  • I/O interface in form of basic terminal
  • Ability to introduce changes to the source code during execution (interactive mode)
  • Ability to return to simulation state befor execution of instruction
  • Ability to automatically execute instructions
  • Basic error detection and display of propable sources of errors

How to run program

Prerequisits

To use this program, it's necessary to install Python interpreter version 3.10, or highier (project was develope and tested with Python 3.11).

How to check, if Python was correctly installed?

To ensure, that Pyhon was correctly installed, perform the following steps in terminal (cmd, PowerShell, Terminal, Bash - depending on the system):

  1. Open terminal
  2. Enter one of the following command
python –version

or

python3 -version

If Python was installed correctly, current version should be returned - ex. Python 3.11.8.

If command wouldn'be be recognized, ensure that:

  • Python was installed and added to environemnt variable PATH,
  • on some systems (ex. macOS/Linux) by default python3 should be used, instead of python.

Additionally, you can run interactive mode by typing:

python

or

python3

After running command you should see something like:

Python 3.11.8 (default, …)

To exit interactive mode, write exit() or press Ctrl + Z (Windows) or Ctrl + D (Linux/macOS).

πŸ“š Official Python documentation can be found at: https://docs.python.org/3/using/index.html


Preparation or virtual environment and library instalation

After successfult instalation of Python interpreter and downloading reposity content, it's necessary to prepare virtuall environment and download libraries. More informatios about process can be found on documentaiton page - for our project everthing will come down to executing those commands in terminal from repo's folder on our machine:

For Linux and MacOS systems:

python3.11 -m pip install venv
python3.11 -m venv my-venv-folder
source my-venv-folder/bin/activate
python3.11 -m pip install -r requirements.txt

For Windows systems:

python -m pip install venv
python -m venv my-venv-folder
my-venv-folder\Scripts\activate
python -m pip install -r requirements.txt

Running and Using the Program

Running and using the program (after correctly installing the libraries and activating the virtual environment) boils down to launching the program with the command (assuming we are in the project directory):

python3.11 main.py

After launching, you should see the main menu:

Welcome Screen GUI

Program is available in English, but screenshots depict version in Polish lanuguage

Working Modes

Analyze File

In this mode, we assume that we have a file which normally compiles but does not work as expected. If we try to run a file containing syntax errors, an error message will be displayed, and an option to run the file in interactive mode will appear.

A correct file load should result in starting the interpreter with a code preview:

File Analysis GUI

To start working, use the Run program button (visible on picture as Uruchom program):


Control Buttons GUI

Program Sections

  • Registers and Flags – shows the internal state of the simulated system, helping to understand the basis of performed operations
  • Code – preview of the file / interactive command, with the highlighted line that will be executed when pressing the Execute Instruction button
  • Segment – displays the state of the processor stack (for simplicity, the stack does not contain a binary representation of the executed program!)
  • Variables – this section allows easy viewing of stack fragments where the user declared variables
  • Terminal – this section enables basic communication between the program and the user through several selected commands

Instruction execution

Manual

Using the Execute Instruction and Return to Previous Line buttons, the user commands the execution of the next instruction or restores the system state to the moment before the previous step was executed.

Automatic Mode

Checking this option will cause automatic progression through subsequent instructions (simulating the user pressing the Execute Instruction button) at selected time intervals specified as Delay.

Operation cycle of program

After loading and initially checking the file, it is possible to execute further commands as well as return to the state before the command was executed. It is possible to view the state of the stack and registers, which allows tracking changes and comparing the behavior with the expected execution of the program. After the program finishes, it is necessary to restart it in order to reload the code (e.g., after making changes).

Interactive Mode

When starting interactive mode, we are greeted by a blank window where we need to enter the code we want to simulate (the exception is opening a file that could not be run in Analysis mode β€” in that case, the file’s contents are loaded automatically).

Welcome Screen GUI

Code analysis is carried out the same way as in analysis mode, with two exceptions:

  1. It is possible to change the values of the registers and the stack directly during program execution.
  2. After execution is stopped, it is possible to make changes to the program code (this will cause the entire program to restart from the beginning).

Supported Commands and Limitations

Due to the complexity of interpreting assembly instructions, certain technical and logistical limitations have been introduced into the program ! This means that not every program written in Assembly can be run or interpreted !

Summary

The general list of supported commands is visible in the section Program's files organization, in the folder Extras/Instructions and descriptions/. Each supported command is saved as a separate .md file named after the supported instruction.

Details

All details regarding the project, limitations, implementation, and the program's operating philosophy can be found in my engineering thesis:


UkΕ‚ad plikΓ³w programu (Program's files organization)

Assembly_interpreter
β”œβ”€ Example assembly programs
β”‚  β”œβ”€ incorrect_programs
β”‚  β”‚  β”œβ”€ engine_cant_use_sp.asm
β”‚  β”‚  β”œβ”€ engine_illegal_operations.s
β”‚  β”‚  β”œβ”€ engine_instruction_not_supported_error.asm
β”‚  β”‚  β”œβ”€ engine_unrecognized_argument_error.asm
β”‚  β”‚  β”œβ”€ engine_wrong_combination_params.asm
β”‚  β”‚  β”œβ”€ engine_wrong_param_types.asm
β”‚  β”‚  β”œβ”€ proc_file_empty_file_no_white_chars.asm
β”‚  β”‚  β”œβ”€ proc_file_empty_file_white_chars.asm
β”‚  β”‚  β”œβ”€ proc_file_file_too_big.asm
β”‚  β”‚  β”œβ”€ proc_file_improper_var_name.asm
β”‚  β”‚  └─ proc_file_incorrect_file_type.txt
β”‚  β”œβ”€ programs_EN
β”‚  β”‚  β”œβ”€ convert_calculate_RPN.asm
β”‚  β”‚  └─ show_time.asm
β”‚  β”œβ”€ programs_PL
β”‚  β”‚  β”œβ”€ obliczanie_ONP_dzialania.asm
β”‚  β”‚  β”œβ”€ pokaz_czas.asm
β”‚  β”‚  └─ text_val.asm
β”‚  └─ test_programs
β”‚     β”œβ”€ all_vaild_add_instructions.asm
β”‚     β”œβ”€ all_valid_flag_setting_instructions.asm
β”‚     β”œβ”€ infinite_loop.asm
β”‚     β”œβ”€ jumps_and_labels.asm
β”‚     β”œβ”€ test_addition_nerar_overflow.asm
β”‚     β”œβ”€ test_int21_ax10.asm
β”‚     β”œβ”€ test_pushes.asm
β”‚     β”œβ”€ test_variable_section.asm
β”‚     └─ working_stack.asm
β”œβ”€ Extras
β”‚  β”œβ”€ Instructions and descriptions
β”‚  β”‚  β”œβ”€ AAA.md
β”‚  β”‚  β”œβ”€ AAD.md
β”‚  β”‚  β”œβ”€ AAM.md
β”‚  β”‚  β”œβ”€ AAS.md
β”‚  β”‚  β”œβ”€ ADC.md
β”‚  β”‚  β”œβ”€ ADD.md
β”‚  β”‚  β”œβ”€ AND.md
β”‚  β”‚  β”œβ”€ CALL.md
β”‚  β”‚  β”œβ”€ CBW.md
β”‚  β”‚  β”œβ”€ CLC.md
β”‚  β”‚  β”œβ”€ CLD.md
β”‚  β”‚  β”œβ”€ CLI.md
β”‚  β”‚  β”œβ”€ CMC.md
β”‚  β”‚  β”œβ”€ CMP.md
β”‚  β”‚  β”œβ”€ CWD.md
β”‚  β”‚  β”œβ”€ DAA.md
β”‚  β”‚  β”œβ”€ DAS.md
β”‚  β”‚  β”œβ”€ DEC.md
β”‚  β”‚  β”œβ”€ DIV.md
β”‚  β”‚  β”œβ”€ IDIV.md
β”‚  β”‚  β”œβ”€ IMUL.md
β”‚  β”‚  β”œβ”€ INC.md
β”‚  β”‚  β”œβ”€ INT.md
β”‚  β”‚  β”œβ”€ JA.md
β”‚  β”‚  β”œβ”€ JAE.md
β”‚  β”‚  β”œβ”€ JB.md
β”‚  β”‚  β”œβ”€ JBE.md
β”‚  β”‚  β”œβ”€ JC.md
β”‚  β”‚  β”œβ”€ JCXZ.md
β”‚  β”‚  β”œβ”€ JE.md
β”‚  β”‚  β”œβ”€ JG.md
β”‚  β”‚  β”œβ”€ JGE.md
β”‚  β”‚  β”œβ”€ JL.md
β”‚  β”‚  β”œβ”€ JLE.md
β”‚  β”‚  β”œβ”€ JMP.md
β”‚  β”‚  β”œβ”€ JNA.md
β”‚  β”‚  β”œβ”€ JNAE.md
β”‚  β”‚  β”œβ”€ JNB.md
β”‚  β”‚  β”œβ”€ JNBE.md
β”‚  β”‚  β”œβ”€ JNC.md
β”‚  β”‚  β”œβ”€ JNE.md
β”‚  β”‚  β”œβ”€ JNG.md
β”‚  β”‚  β”œβ”€ JNGE.md
β”‚  β”‚  β”œβ”€ JNL.md
β”‚  β”‚  β”œβ”€ JNLE.md
β”‚  β”‚  β”œβ”€ JNO.md
β”‚  β”‚  β”œβ”€ JNP.md
β”‚  β”‚  β”œβ”€ JNS.md
β”‚  β”‚  β”œβ”€ JNZ.md
β”‚  β”‚  β”œβ”€ JO.md
β”‚  β”‚  β”œβ”€ JP.md
β”‚  β”‚  β”œβ”€ JPE.md
β”‚  β”‚  β”œβ”€ JPO.md
β”‚  β”‚  β”œβ”€ JS.md
β”‚  β”‚  β”œβ”€ JZ.md
β”‚  β”‚  β”œβ”€ LOOP.md
β”‚  β”‚  β”œβ”€ LOOPE.md
β”‚  β”‚  β”œβ”€ LOOPNE.md
β”‚  β”‚  β”œβ”€ LOOPNZ.md
β”‚  β”‚  β”œβ”€ LOOPZ.md
β”‚  β”‚  β”œβ”€ MOV.md
β”‚  β”‚  β”œβ”€ MUL.md
β”‚  β”‚  β”œβ”€ NEG.md
β”‚  β”‚  β”œβ”€ NOP.md
β”‚  β”‚  β”œβ”€ NOT.md
β”‚  β”‚  β”œβ”€ OR.md
β”‚  β”‚  β”œβ”€ POP.md
β”‚  β”‚  β”œβ”€ POPA.md
β”‚  β”‚  β”œβ”€ POPF.md
β”‚  β”‚  β”œβ”€ PUSH.md
β”‚  β”‚  β”œβ”€ PUSHA.md
β”‚  β”‚  β”œβ”€ PUSHF.md
β”‚  β”‚  β”œβ”€ RCL.md
β”‚  β”‚  β”œβ”€ RCR.md
β”‚  β”‚  β”œβ”€ RET.md
β”‚  β”‚  β”œβ”€ ROL.md
β”‚  β”‚  β”œβ”€ ROR.md
β”‚  β”‚  β”œβ”€ SAL.md
β”‚  β”‚  β”œβ”€ SAR.md
β”‚  β”‚  β”œβ”€ SBB.md
β”‚  β”‚  β”œβ”€ SHL.md
β”‚  β”‚  β”œβ”€ SHR.md
β”‚  β”‚  β”œβ”€ STC.md
β”‚  β”‚  β”œβ”€ STD.md
β”‚  β”‚  β”œβ”€ STI.md
β”‚  β”‚  β”œβ”€ SUB.md
β”‚  β”‚  β”œβ”€ TEST.md
β”‚  β”‚  β”œβ”€ XCHG.md
β”‚  β”‚  β”œβ”€ XOR.md
β”‚  β”‚  β”œβ”€ _ 16 bit Assembly Interpreter.pdf
β”‚  β”‚  └─ _ Interpreter Asemblera 16 bit.pdf
β”‚  └─ Utilities
β”‚     β”œβ”€ flag_converter.py
β”‚     └─ show_misspelled.py
β”œβ”€ README.md
β”œβ”€ generate_markdow_for_supported_instructions.py
β”œβ”€ main.py
β”œβ”€ program_code
β”‚  β”œβ”€ __init__.py
β”‚  β”œβ”€ assembly_instructions
β”‚  β”‚  β”œβ”€ __init__.py
β”‚  β”‚  β”œβ”€ arithmetic_instrunctions.py
β”‚  β”‚  β”œβ”€ bit_movement_instructions.py
β”‚  β”‚  β”œβ”€ data_movement_instructions.py
β”‚  β”‚  β”œβ”€ flag_setting_instructions.py
β”‚  β”‚  β”œβ”€ flow_control_instructions.py
β”‚  β”‚  β”œβ”€ interrupt_instructions.py
β”‚  β”‚  β”œβ”€ jump_instructions.py
β”‚  β”‚  β”œβ”€ logical_instrunctions.py
β”‚  β”‚  └─ stack_instructions.py
β”‚  β”œβ”€ code_handler.py
β”‚  β”œβ”€ configs
β”‚  β”‚  β”œβ”€ color_palette.json
β”‚  β”‚  └─ names.json
β”‚  β”œβ”€ custom_gui_elements.py
β”‚  β”œβ”€ custom_message_boxes.py
β”‚  β”œβ”€ engine.py
β”‚  β”œβ”€ errors.py
β”‚  β”œβ”€ flag_register.py
β”‚  β”œβ”€ gui.py
β”‚  β”œβ”€ hardware_memory.py
β”‚  β”œβ”€ hardware_registers.py
β”‚  β”œβ”€ helper_functions.py
β”‚  β”œβ”€ history.py
β”‚  └─ preprocessor.py
β”œβ”€ readme_pictures
β”‚  β”œβ”€ interactive_mode.png
β”‚  β”œβ”€ analiza_pliku.png
β”‚  β”œβ”€ ekran_powitalny_gui.png
β”‚  β”œβ”€ podpowiedzi.png
β”‚  └─ przyciski sterujaΜ¨ce.png
└─ requirements.txt

About

A small GUI app, to let people practice x86 assembly (Intel syntax)

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published