mesyeti
Home | Page list | Contact me
Nitron
Nitron is a 32-bit stack based virtual machine. Its goal is to work as an operating system for microcontrollers and maybe even desktop computers.
Instead of being restricted to its own memory, it has access to the host machine's memory. This means it can easily interact with the MMIO you may find on microcontrollers, meaning you can do low level programming in it.
Ideas
- Have a numbered drive system like I have for the resource manager in Arkas Engine
- Have a read only file system stored on the microcontroller flash (same file system as Arkas Engine archives)
- Allow the user to connect an SD card reader/writer via GPIO to save their work
GitHub
CPU
The opcode takes up the lower 7 bits of the instruction. If the highest bit is set to 1, then the 32 bit value after the instruction is pushed to the stack before the instruction is executed.
Registers
Registers:
- 0 - General purpose
- 1 - General purpose
- 2 - General purpose
- 3 - General purpose
- 4 - General purpose
- 5 - General purpose
- 6 - General purpose
- 7 - General purpose
Instructions
0x00- NOP0x01- ADD0x02- SUB0x03- MUL0x04- DIV0x05- MOD0x06- R2D0x07- D2R0x08- DUP0x09- OVER0x0A- DROP0x0B- ROT0x0C- AREA0x0D- READ0x0E- WRITE0x0F- JUMP0x10- JNZ0x11- HALT0x12- ECALL0x13- REG0x14- WREG0x15- READ80x16- WRITE80x17- READ160x18- WRITE160x19- JZ0x20- DIVMOD0x21- EQU0x22- LESS0x23- GREATER0x24- LE0x25- GE0x26- NEG0x27- AND0x28- XOR0x29- OR0x2A- NOT0x2B- SWAP0x2C- CALL0x2D- RET0x2E- FARCALL
System calls
The higher 16 bits is the section, the lower 16 bits is the call.
Section 0x0000 - User calls
This section has some space for user defined calls
Section 0x0001 - IO
0x00- Print character:( ch -- )0x01- Print string:( string len -- )0x02- Print hex:( num -- )0x03- Input char:( -- ch )0x04- Print null terminated string( string -- )0x05- Input line:( string* maxLength -- )0x06- Print decimal:( num -- )
Section 0x0002 - Memory
0x00- Alloc:( size -- ptr )0x01- Realloc( ptr size -- ptr )0x02- Free( ptr -- )
Section 0x0003 - VM
0x00- Dump:( -- )0x01- Get user calls amount( -- size )0x02- Removed0x03- Error to string( error -- str* )0x04- Dump memory:( addr size -- )0x05- Get memory usage:( -- used total )0x06- Set area pointer:( ptr -- )0x07- Get area pointer:( -- ptr )0x08- Nothing( -- )0x09- Run file( path -- success )
Section 0x0004 - Assembler
0x00- Assemble( completion? source assembler* -- size success )- Source must be null terminated
0x01- New assembler( -- asm*)0x02- Free assembler( asm* -- )0x03- Get assembler binary pointer( asm* -- bin* )0x04- Set assembler area( area size asm* -- )0x05- Get assembler data pointer( asm* -- data* )0x06- Set assembler data pointer( data* asm* -- )0x07- Set assembler binary( bin* size asm* -- )0x08- Free incomplete assembler references( asm* -- )0x09- Reset assembler binary length( asm* -- )0x0a- Set assembler binary pointer( bin* asm* -- )0x0b- Extend assembler binary( size asm* -- success )0x0c- Set assembler mode( code=0,data=1 asm* -- )0x0d- Reset assembler binary( asm* -- )0x0e- Freeze assembler labels( asm* -- )0x0f- Get assembler binary( asm* -- bin* )
Section 0x0005 - Filesystem
0x00- Read file( path -- size contents* success )0x01- Read text file( path -- contents* success )0x02- Write file( path size data -- success )0x03- Write text file( path str -- success )