Home - MariEliseeva/project GitHub Wiki
I had to create a format in which we can describe AVR-microcontroller commands and make an emulator, which takes the desctiption and execute commands using it. Emulator also have to return some information about executing.
Emulator can calculate some simple actions -- set values, check a condition, calculate ariphmetic expressions. Using these actions we can create all other commands.
An emulator reads a description of commans and for each name remembers arguments and instructions. Then reads file with a code and remembers for each line name of command in it and given values.
Than called method, which executes commands line by line. The method returns which line should we go next.
Inside - making an unordered_map, which remembers value of argument by its name. Then needed actions are performing.
Each action is a condition (not always), an expression and where should we put a result.
So in any action - calculation a condition, calculation right part of expression and putting the result to the left part.
After executing a command program counter increases and returns value to main.
The information we can take during the running is time of workingm, which registers and how were changed. Also we can stop after definied lines and ask an info after stopping.
make - build, ./avr - run
make clean - deleting *o, avr
First line - memory size in bytes, mininum is 64, so if you give less it'll be 64 anyway.
Second line - time in milliseconds for one tact.
Then lines with commands: Name, space, arguments divided by commas or "-" if no arguments, then instructions, divided by commas. In the end - how much tact is the command executed.
Description ends with a new line.
All commands' names are different.
Arguments - registers' numbers or constants.
Registers - two symbols: "R" + one small letter (ex: Rr, Rd).
Constants - K8 (8 bit), K6(6 bit), b(3 bit), s(3 bit), P(6 bit), k(unnknown), q(6 bit).
Actions - left part, "=", right part. May be a condition: if(expression), 0 - false, not 0 - true.
May set a value in registers by number, in paired-registers, in definited bits, in flags C, Z, N, V, S, H, T, I, in memory by adress, in program counter, in stack.
Value or condition - expression with everything above and with constants or just numbers.
New command - new line
Command - name, space, argument divided by commas. May be a constant expression (ex: 2 + 2).
Operations: +, -, *, /, |, &, ||, &&, ==, <, >, !, ~, ^. No unary minus, use 0-x for it.
make test - build unit-tests.
./bin/test - run unit-tests.
If complete - "All tests passed.",
If no - how much errors, where exactly they are.
Two functional tests - just commands for usual microcontroller and Fibonacci numbers.
Run (build- make):
./avr -test f_test/input
./avr -test f_test/input_fib
In f_test/output - a result.
Expected for first test - f_test/output_res, for second - f_test/output_fib_res.
Working code is on branch_with_project