Skip to content

StijnOost/ASM-interpreter

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

88 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

ARM Cortex M0 interpreter

Features

  • Implements basic instructions like MOV, LDR(H/B), STR(H/B), PUSH, POP, ADD, SUB, CMP
  • Supports Branch and Branch-link instructions as well as conditional branch instructions
  • Error handling for both the parse and run steps, showing the call stack for runtime errors
  • A visualizer to show the registers of the simulated processor and the current instruction and interact with the memory of the simulated processor

Conditional branch instructions

These conditional branch instructions are supported:

  • BCC/BCLO: carry clear / unsigned lower
  • BCS/BHS: Carry set / unsigned higher or same
  • BEQ: Equal / zero
  • BGE: Signed greater than or equal
  • BGT: Signed greater than
  • BHI: Unsigned higher
  • BLE: Signed less than or equal
  • BLS: Unsigned lower or same
  • BLT: Signed less than
  • BMI: Minus / negative
  • BNE: Not equal / not zero
  • BPL: Plus / zero or positive
  • BVC: No overflow
  • BVS: Overflow

settings

To use the Interpreter, The settings in the main.py file must be changed:

  • Change the string after fileName to the name of the file you want to run the interpreter with.
  • By changing useGUI to False, the visualizer can be disabled entirely. this is useful when it is not needed because the program will run faster without the visualizer.
  • The stack size can be changed by changing the number after stackSize. The default setting is 0x40, which is 64 byes. Changing it to 0x400 will result in a stack of 1 KB.
  • The interpreter needs to know what subroutine to call first. This can be set with the startLabel variable. The default value is '_start'

error detection

To enable the user to find problems in their code easily, clear errors are thrown when problems occur. When a runtime error occurs, a stacktrace is printed to make it easy to trace the problem back. In the console, the error messages should be red. This works in PyCharm but does not seem to work in the Windows terminal. Because this is purely a visual bug, this has not yet been fixed.

alt text

Note: to create this image, the stack size has been set as low as 16 bytes

Printing to the console

Printing to the console is possible by using the subroutines print_char and print_int:

bl print_char

bl print_int

The visualizer

Using the visualizer, the register processor can be viewed easily to make debugging code easier. It is also possible to single-step the program to see exactly when the program broke. The current instruction and its location in the source code is shown to make it easy to find the instruction in the source code.

alt text

The icons for New, Open, Save and Save As have been sourced from here: https://findicons.com/pack/566/isimple_system

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Packages

No packages published

Languages

  • Python 99.7%
  • Shell 0.3%