Hello everyone, today we will write a simple yet super powerful virtual machine from scratch in C programming language I know it seems Bis and scary! that is what it was for me at the beginning but let's break that down!
What is a Virtual Machine aka VM?
a
virtual machine is just like a normal computer machine but simulated
programatically, so it is a computer that we simulate using lines of
code.
it also simulates the way computer behaves in case of cpu and other common components such as IO , file and memory management. It also understands programs written in a certain machine language or assembly language, and we will create a cutom language that we will later use to program the machine in!
Step 1 - setting everything up
if we are going to program in C then you will of course need a compiler to compile your programs, you can use whatever compiler or ide you prefere but I like to use a text editor and write my own makefiles for compilation and I will be using GNU GCC compiler that comes with the CodeBlocks IDE.
so,
make a simple directory and create a simple text file for example "myfile.txt" then rename it to "Makefile" this is if you will follow me and not using an IDE if otherwise just ignore this.
then paste this little text inside Makefile
# program compilation Recipe
this will compile the program when we call make fron the terminal (in UNIX or MAC systems) or nmake in case of windows.
if we are going to program in C then you will of course need a compiler to compile your programs, you can use whatever compiler or ide you prefere but I like to use a text editor and write my own makefiles for compilation and I will be using GNU GCC compiler that comes with the CodeBlocks IDE.
so,
make a simple directory and create a simple text file for example "myfile.txt" then rename it to "Makefile" this is if you will follow me and not using an IDE if otherwise just ignore this.
then paste this little text inside Makefile
# program compilation Recipe
compile:
gcc -Wall main.c -o VM
gcc -S -o asm.s main.c
this will compile the program when we call make fron the terminal (in UNIX or MAC systems) or nmake in case of windows.
تعليقات
إرسال تعليق