# hovm **Repository Path**: foreverofprogrammer/hovm ## Basic Information - **Project Name**: hovm - **Description**: Ho虚拟机 - **Primary Language**: C - **License**: GPL-2.0 - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 3 - **Forks**: 0 - **Created**: 2024-01-25 - **Last Updated**: 2026-09-27 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README # HOVM A lightweight virtual machine implementation library. ## Project Overview HOVM is a lightweight Virtual Machine (VM) library implemented in C, providing basic functionalities such as instruction parsing, memory management, register operations, and arithmetic computations. This project aims to offer a simple and extensible virtual machine framework for educational and research purposes. ## Features - **Instruction Parsing**: Supports parsing bytecode or script commands into executable instruction structures - **Memory Management**: Provides dynamic memory allocation, deallocation, and access functions - **Register Operations**: Simulates initialization, reading, and updating of CPU-like registers - **Arithmetic Operations**: Supports basic mathematical operations including addition, subtraction, multiplication, and division - **File Operations**: Supports reading binary files and retrieving file sizes ## File Structure | File | Description | |------|-------------| | `main.c` | Program entry point | | `command.c` / `command.h` | Implementation of command parsing and execution | | `file.c` / `file.h` | Functions related to file operations | | `memory.c` / `memory.h` | Virtual memory management | | `registers.c` / `registers.h` | Register operations | | `vmmath.c` / `vmmath.h` | Mathematical operation functions | | `vmmalloc.c` / `vmmalloc.h` | Memory allocation management | ## Compilation and Execution ### System Requirements - A C compiler (e.g., GCC) - Windows or Linux system ### Compilation Steps On Windows, you can use the provided batch file for quick compilation: ```bash dll.bat ``` Or compile manually: ```bash gcc -o hovm main.c command.c file.c memory.c registers.c vmmath.c vmmalloc.c ``` ### Execution After compilation, run the generated executable file to start the virtual machine. ## Usage Guide ### Basic Concepts - **Memory**: A contiguous memory space allocated by the virtual machine for storing data and state - **Registers**: Fast-access storage units within the virtual machine, analogous to CPU registers - **Command**: An instruction to be executed, comprising an operation type and operands ### API Overview ```c // Create and release memory Memory create_memory(unsigned long memory_size); void release_memory(Memory memory); // Memory access unsigned char get_memory(Memory memory, unsigned long address); // Register operations void init_registers(registers *r); unsigned char get_register(registers r, unsigned char r_id, unsigned char default_value); void update_register(registers *r, unsigned char r_id, unsigned char r_value); // Command execution int execute_command(Command cmd, registers *r, Memory memory); // Mathematical operations Add add(unsigned short add1, unsigned short add2); unsigned short sub(unsigned short sub1, unsigned short sub2); unsigned short mul(unsigned short mul1, unsigned short mul2); Div division(unsigned short div1, unsigned short div2); ``` ## Examples For additional usage examples, refer to the implementations in the source code. ## Open Source License For details about the license, please refer to the LICENSE file.