嵌入式虚拟机CarpVM.zip

  • U8_117311
    了解作者
  • 45.5KB
    文件大小
  • 文件格式
  • 0
    收藏次数
  • VIP专享
    资源类型
  • 0
    下载次数
  • 2022-05-25 17:46
    上传日期
CarpVM 是一个用 C 语言编写的小型虚拟机。可以嵌入在应用程序中使用。 包含的指令集有: HALT (code): Halts and attempts to clean up stack, data memory, and label memory before exiting with given exit code. NOP (): Does nothing. Seriously. LOAD (reg, val): Loads given integer value into given register. MOV (dst, src): Copies contents of src register into dst register. ADD (): Pops the top two integers from the stack and pushes their sum. SUB (): Pops the top two integers from the stack and pushes the difference (lower minus upper). MUL (): Pops the top two integers from the stack and pushes their product. MOD (rega, regb): Computes rega % regb and stores in ERX. NOT (reg): Computes bitwise NOT of reg and stores in reg. XOR (): Pops the top two integers from the stack and XORs them. OR (): Pops the top two integers from the stack and ORs them. AND (): Pops the top two integers from the stack and ANDs them. INCR (reg): Increments value in given register. DECR (reg): Decrements value in given register. INC (): Increments the value at the top of the stack. DEC (): Decrements the value at the top of the stack. PUSHR (reg): Pushes value in given register. PUSH (val): Pushes given value. POP (val): Pops an integer from the stack and dumps it into GBG. CMP (): Pops the top two integers from the stack and checks if equal. 0 means equal. Result will be pushed onto the stack. MOV (rega, regb): Move value in rega to regb. JZ (addr): Jumps to given absolute address if top of the stack is 0. RJZ (diff): Adds differential to current EIP (relative jump) if top of the stack is 0. JNZ (addr): Jumps to given absolute address if top of the stack is not 0. RJNZ (diff): Adds differential to current EIP (relative jump) if top of the stack is not 0. JMP (addr): Jumps to given absolute address. RJMP (diff): Adds differential to current EIP (relative jump). DBS (key, val): Sets data memory at key (string pointer) to given value. DBG (key, reg): Gets value from data memory at key (string pointer) and dumps it into given register. CALL (key, nargs): Save state and set EIP to value in data memory at key. RET (val): Push return value and load state. PREG (reg): Prints contents of given register. PTOP (): Peeks top of stack and prints top value. 标签:CarpVM
carp-master.zip
  • carp-master
  • .travis.yml
    112B
  • .gitmodules
    95B
  • tests
  • ht.c
    677B
  • registers.c
    1.2KB
  • tests.h
    65B
  • instr
  • tests_instr.h
    196B
  • register.c
    771B
  • halt.c
    636B
  • stack.c
    3.2KB
  • stack.c
    1.2KB
  • libtap
  • TODO.md
    2KB
  • src
  • lexer.h
    150B
  • reg_lookup.c
    4.8KB
  • instructions.h
    868B
  • main.c
    3.1KB
  • instructions.c
    4KB
  • tokenizer.h
    637B
  • machine.h
    2.3KB
  • lexer.c
    2.7KB
  • registers.c
    2.2KB
  • instr_lookup.c
    6.3KB
  • tokenizer.c
    4.9KB
  • registers.h
    1.1KB
  • machine.c
    4.4KB
  • lib
  • ht.c
    4.3KB
  • messages.h
    477B
  • types.h
    127B
  • ht.h
    722B
  • stack.c
    2.5KB
  • stack.h
    623B
  • extras
  • print_codes.c
    169B
  • carp-mode
  • carp-mode.el
    1.2KB
  • examples
  • c
  • call.c
    579B
  • simple.c
    951B
  • esp.c
    476B
  • data.c
    496B
  • carp
  • countdown.carp
    66B
  • factorial.carp
    79B
  • store.carp
    102B
  • fibonacci.carp
    146B
  • empty.carp
    0B
  • add.carp
    41B
  • call.carp
    91B
  • reg.carp
    121B
  • gcd.carp
    169B
  • SYNTAX.md
    618B
  • .gitignore
    69B
  • fuzz
  • no-main.carp
    7B
  • main-label-only.carp
    6B
  • halt-1.carp
    13B
  • Makefile
    2.2KB
  • README.md
    6.1KB
  • LICENSE.txt
    34.3KB
内容介绍
# THIS PROJECT IS UNSTABLE AND DEPRECATED I have since started slow work on a more stable, better thought-out project called [RabbitVM](https://github.com/rabbitvm/rabbit). It doesn't quite have the same level of documentation but it should work much better. # CarpVM This is a project I've been slowly working on for about half a year now. The goal is to try and build a small (and decently reliable) VM from the ground up, learning more and more C as I go. Right now there are instructions, registers, a stack, data memory, and calls. Not sure if recursion works... it should in theory. Haven't tested. CONSIDER THIS PRE-ALPHA SOFTWARE. Things change more than they do in Rust! [![Build Status](https://travis-ci.org/tekknolagi/carp.svg?branch=master)](https://travis-ci.org/tekknolagi/carp) &nbsp; ![](https://ga-beacon.appspot.com/UA-47678422-4/tekknolagi/carp) &nbsp; [![Flattr this](http://api.flattr.com/button/flattr-badge-large.png)](http://flattr.com/thing/3268893/tekknolagicarp-on-GitHub) ## Installation ### Getting Carp **If you already have a local copy (cloned before submodule was added)** * `git fetch` * `git rebase` * `git submodule init` * `git submodule update` **If you don't already have a local copy** * `git clone --recursive` NOTE: If `git submodule status` doesn't return a SHA1 hash and repository name, you have a problem. NOTE: Recursive clone is for testing library. If not included, tests will not build. ### Building Carp 1. `make` 2. `make test` (optional) 3. `make install` 4. `make clean` (optional) #### Tested Machines Arch (bit) | OS (with version, name) | Compiler (with version) ---------- | ----------------------- | ----------------------- 64-bit | Ubuntu 12.04 (precise) | gcc 4.6.3 64-bit | Ubuntu 14.04 (trusty) | gcc 4.8.2 32-bit | Ubuntu 14.04 (trusty) | gcc 4.8.2 64-bit | OS X 10.9.4 (Mavericks) | clang 3.2 32-bit | OS X 10.9.4 (Mavericks) | gcc 4.2.1 64-bit | Arch Linux 3.13.6-1 | clang 3.4.2 64-bit? | Arch Linux 3.13.6-1 | gcc 4.9.0 20140604 ## Use NOTE: See `carp -h` for help with command-line options. ### Interpreter 1. Write a Carp file - see [SYNTAX.md](http://github.com/tekknolagi/carp/tree/master/SYNTAX.md). More formal spec coming. 2. Run `./carp.out -f your_file.carp`. ### API 1. Include `carp/carp_machine.h` in your program. 2. Run `gcc program.c /usr/local/lib/libcarp.a -o program.out`. ## Instruction set Opcode | Arguments | Description ------ | --------- | ----------- HALT | exit code | Sets `ext` to given code, halts, and attempts to clean up stack, data memory, and label memory. NOP | | Does nothing. Seriously. LOADR | reg, val | Loads given integer value into given register. LOAD | diff | Loads value at location `fp` + diff in the stack. STORE | diff, val | Stores value at location `fp` + diff. MOV | dst, src | Copies contents of src register into dst register. ADD | | Pops the top two integers from the stack and pushes their sum. SUB | | Pops the top two integers from the stack and pushes the difference (lower minus upper). MUL | | Pops the top two integers from the stack and pushes their product. MOD | | Pops the top two integers from the stack and pushes lower % upper. SHR | | Pops the top two integers from the stack and pushes lower >> upper. SHL | | Pops the top two integers from the stack and pushes lower << upper. NOT | | Pops top integer from stack and pushes bitwise NOT of that integer. XOR | | Pops the top two integers from the stack and pushes bitwise XOR.. OR | | Pops the top two integers from the stack and pushes bitwise OR. AND | | Pops the top two integers from the stack and pushes bitwise AND. INCR | reg | Increments value in given register. DECR | reg | Decrements value in given register. INC | | Increments the value at the top of the stack. DEC | | Decrements the value at the top of the stack. PUSHR | reg | Pushes value in given register. PUSH | val | Pushes given value. POP | reg | Pops an integer from the stack and dumps it into given register. CMP | | Pops the top two integers from the stack and checks if equal. 0 means equal. Pushes result. LT | | Pops the top two integers from the stack and checks if lower < upper. Pushes result. GT | | Pops the top two integers from the stack and checks if lower > upper. Pushes result. JZ | addr | Jumps to given absolute address if top of the stack is 0. RJZ | diff | Adds differential to `ip` (relative jump) if top of the stack is 0. JNZ | addr | Jumps to given absolute address if top of the stack is not 0. RJNZ | diff | Adds differential to `ip` (relative jump) if top of the stack is not 0. JMP | addr | Jumps to given absolute address unconditionally. RJMP | diff | Adds differential to `ip` (relative jump) unconditionally. CALL | key/addr | Save state and set IP to value in data memory at key. Function may return value in `ax`. RET | | Put top of the stack into `ax` and load previous state. PREG | reg | Prints contents of given register. PTOP | | Peeks top of stack and prints top value. ## Registers Name | Purpose ---- | ------- `r0` ... `r9` | General purpose. `ax` | Return value for user-defined function. `bx`, `cx`, `dx`, `rx` | ... something in the future. Just taking up space for now. `ip` | Instruction pointer. Used for keeping place in code, gotos, calling, etc. `sp` | Stack pointer. `fp` | Frame pointer. Used to keep state for function calls. `gbg` | Garbage register mainly used for popping. `run` | Boolean - is machine running? `ext` | Exit code. ## How to contribute One way: 1. Check out the TODO.md file to see if anything needs doing. 2. Write some code (following existing implicit style) and submit a pull request. Another way: 1. Write some code for a feature you want to exist and submit a pull request. ## License GPLv3. See [LICENSE.txt](http://github.com/tekknolagi/carp/tree/master/LICENSE.txt).
评论
    相关推荐
    • 嵌入式
      嵌入式 芝麻实验室
    • 嵌入式课件
      嵌入式课件,很详细,我们的课件 嵌入式课件,很详细,我们的课件
    • 嵌入式课件
      嵌入式课件PPT 通过讲义可了解嵌入式开发的基础内涵代码及具体操作讲解
    • 嵌入式课件
      这是学校的嵌入式课件,讲的比较详细,有问题欢迎大家到我空间留言或博客交流哦
    • 嵌入式课件
      嵌入式授课的ppt文件,是初学嵌入式的学习文件,适合初学者
    • 嵌入式课件
      大学嵌入式系统的课件,内容比较详细,学完后入门不是问题。
    • 嵌入式开发
      嵌入式开发方面的非常好的书籍,希望上传共享,请大家积极点评。
    • 嵌入式教程
      嵌入式教程,让你全面了解嵌入式,西工大出品很不错的哦~~~
    • 嵌入式
      嵌入式
    • 嵌入式开发
      ARM应用系统开发详解.pdf C&C++嵌入式系统编程.pdf 嵌入式处理器体系结构发展漫谈.pdf 嵌入式系统的C程序设计.pdf 嵌入式操作系统综述.pdf