To use this program, you need to write code to a file asm.txt, in this case, the code must be written using a specific syntax:
- CRT (create) is a command that should be written at the beginning of the program code, it creates a stack for the processor;
- IN - command to enter a number from the keyboard (the number is put on the processor stack);
-
- PUSH 0 - puts the number 0 on the processor stack;
- PUSH ax - puts a number from the ax register on the processor stack;
- PUSH [1] - puts a number from RAM at address 1 on the processor stack;
- PUSH [ax] - puts a number from RAM to the address ax;
- ADD - adds two numbers from the processor stack and puts the result back;
- SUB - subtraction;
- MUL - multiplication;
- DIV - division;
- OUT - takes an element from the processor stack and displays it on the screen;
- HLT is a command that is written at the end of the program, it clears the memory that the processor stack occupied;
- POP - command is an analog of PUSH, which takes an element from the processor stack and puts it in a register or RAM;
- :label - label;
- JMP label - switch to label label;
- JA label - switch to label label if the penultimate number in the processor stack is greater than the last one;
- JAE label (>=);
- JB label (<);
- JBE label (<=);
- JE label (==);
- JNE label (!=);
- CALL nameFunction - the command switches to the nameFunction label, and the execution of the function code begins;
- RET is a command that is written inside a function that starts with the nameFunction label and returns the execution of the program to the command following the CALL nameFunction command;
- SQRT is a square root command that takes the last number from the processor stack and returns the result of the operation in its place;
- DRAW - command to draw the contents of RAM;
- MOVE - movement command (experimental command that needs improvement);
- P_CDOT - is a command that displays the character '*';
- P_SPACE - a command that displays the symbol ' ';
- NEW_LINE - a command that moves the cursor to a new line.
Assembler/main.cpp - a file that converts code from a file asm.txt in binary code and writes it to a file code.txt.
CPU/main.cpp - a file that executes code from a file code.txt and displays the result of the program on the screen.
Disassembler/main.cpp - a file that converts binary code from a code file.txt into the program text and writes it to a file asm.txt (the code of this program is proposed to be written to the reader as a training task).
You can only call the execution of a file CPU/main.cpp , since programs are called inside this program Assembler/main.cpp and Disassembler/main.cpp using the system() function, which is done for the convenience of the user.
include/ is a folder with header files *.h that are used inside programs.
testPrograms/ is a folder with examples of programs written using the syntax described above.