Skip to content
/ CPU Public

Processor simulator implemented in the C programming language

Notifications You must be signed in to change notification settings

vihlancevk/CPU

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

9 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

CPU

Program description

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:

  1. CRT (create) is a command that should be written at the beginning of the program code, it creates a stack for the processor;
  2. 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;
  3. ADD - adds two numbers from the processor stack and puts the result back;
  4. SUB - subtraction;
  5. MUL - multiplication;
  6. DIV - division;
  7. OUT - takes an element from the processor stack and displays it on the screen;
  8. HLT is a command that is written at the end of the program, it clears the memory that the processor stack occupied;
  9. POP - command is an analog of PUSH, which takes an element from the processor stack and puts it in a register or RAM;
  10. :label - label;
  11. JMP label - switch to label label;
  12. JA label - switch to label label if the penultimate number in the processor stack is greater than the last one;
  13. JAE label (>=);
  14. JB label (<);
  15. JBE label (<=);
  16. JE label (==);
  17. JNE label (!=);
  18. CALL nameFunction - the command switches to the nameFunction label, and the execution of the function code begins;
  19. 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;
  20. 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;
  21. DRAW - command to draw the contents of RAM;
  22. MOVE - movement command (experimental command that needs improvement);
  23. P_CDOT - is a command that displays the character '*';
  24. P_SPACE - a command that displays the symbol ' ';
  25. 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).

Using the program

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.

Additional information

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.

About

Processor simulator implemented in the C programming language

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published