Microcontroller Interpreter

Command Manual

This interpreter simulates a simple microcontroller environment, allowing users to define variables, perform arithmetic operations, and implement conditional logic. This tool is designed for educational purposes, providing a hands-on way to learn about basic programming concepts. Note that while this simulation mimics some basic features of a microcontroller, it does not support attaching components.

Accumulator

The accumulator (acc) is a special variable used to store the results of recent arithmetic operations. It acts as a temporary storage space that holds the output of calculations, allowing users to reference the result in subsequent commands. The value of acc can be printed to the console or used in conditional statements, making it a crucial element in the flow of the program.

Comments

Comments can be added to the code using the # syntax. Any text following # on the same line will be ignored by the interpreter. This feature is useful for adding notes or explanations to your code, making it easier to understand and maintain.

Available Commands

Command Description Example
def name value Defines a variable with an initial value. def x 10
set name value Sets a variable to a new value. set x 15
mov src dst Moves the value from one variable to another. mov x y
inc name Increments a variable by 1. inc x
dec name Decrements a variable by 1. dec x
add var var Adds two variables and stores the result in the accumulator. add x y
sub var var Subtracts the second variable from the first and stores the result in the accumulator. sub y x
mul var var Multiplies two variables and stores the result in the accumulator. mul x y
div var var Divides the first variable by the second and stores the result in the accumulator. div x y
mod var var Divides the first variable by the second, gets the remainder, and stores the result in the accumulator. mod x y
print var Outputs the value of a variable or the accumulator. print acc
printstr string Outputs a string directly to the console. printstr "Hello, World!"
if condition var/value var/value Begins a conditional block based on a condition (equality (eq), inequality (neq), greater than (gt), less than (lt)). if eq x y
elseif condition var/value var/value Introduces an alternative conditional block. elseif gt x y
else Provides an alternative action if all preceding conditions are false. else
endif Marks the end of a conditional block. endif
loop count Begins a loop that runs for a specified number of times. The variable index is a reserved value if you use a loop. loop 5
endloop Marks the end of a loop block. endloop

Example Code

The following example demonstrates the use of some commands in a single program:

def x 10
def y 20
def i 0

add x y

set y 25

if eq acc 30
    print x
elseif eq acc 40
    print y
endif

loop 5
    inc i
    print i
endloop

mov x y