Skip to content

Hatoribocchi/virtual-machine

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

6 Commits
 
 
 
 

Repository files navigation

Example:

int main( )
{
    VM::CProgramBuilder Builder;

    const std::vector<uint8_t>& vecBytecode = Builder
        .Instruction( VM::EInstructions::PUSH )
        .Bit32( 10 )

        .Instruction( VM::EInstructions::PUSH )
        .Bit32( 20 )

        .Instruction( VM::EInstructions::ADD )

        .Instruction( VM::EInstructions::POPREG )
        .Bit8( VM::ERegisters::R0 )

        .Instruction( VM::EInstructions::PUSH )
        .Bit32( 5 )

        .Instruction( VM::EInstructions::PUSHREG )
        .Bit8( VM::ERegisters::R0 )

        .Instruction( VM::EInstructions::ADD )

        .Instruction( VM::EInstructions::POPREG )
        .Bit8( VM::ERegisters::R0 )

        .Instruction( VM::EInstructions::PUSH )
        .Bit32( 35 )

        .Instruction( VM::EInstructions::PUSHREG )
        .Bit8( VM::ERegisters::R0 )

        .Instruction( VM::EInstructions::CMP )

        .Instruction( VM::EInstructions::JNZ )
        .Bit32( 0 )

        .Instruction( VM::EInstructions::HALT )
        .GetBytecode( );

    VM::CMachine Machine( vecBytecode );

    try
    {
        Machine.Execute( );
    }
    catch ( const std::exception& e )
    {
        std::cerr << "VM error: " << e.what( ) << std::endl;
    }

    return 0;
}

About

simple vm

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages