Created
November 10, 2011 12:59
-
-
Save itsbth/1354797 to your computer and use it in GitHub Desktop.
Uploaded by UploadToGist for Sublime Text 2
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #include <stdio.h> | |
| #include <stdbool.h> | |
| #define VERBOSE | |
| #include "vm.h" | |
| unsigned int code[] = { | |
| /*0*/ INSTR_MOV, VM_REG(0), VM_CODE_MASK | 9, | |
| /*3*/ INSTR_ADDI, VM_REG(0), VM_CODE_MASK | 10, | |
| /*6*/ INSTR_INT, 11 | VM_CODE_MASK, 0, | |
| /*9*/ 10, 20, 1, | |
| /*b*/ 0, 0, 0 | |
| }; | |
| bool flag = true; | |
| void intr_hnd(vm_state s) { | |
| flag = false; | |
| printf("10 + 20 = %u\n", vm_get_int(s, VM_REG(0))); | |
| } | |
| int main() { | |
| vm_state state = vm_create_state(code, sizeof(code), 1024); | |
| vm_register_interrupt(state, 1, intr_hnd); | |
| while (flag) { | |
| vm_run_instruction(state); | |
| } | |
| return 0; | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| ➜ radevm ./main | |
| 0: MOV VM_REG(0x0), VM_CODE(0x9) [0, 10] | |
| 3: ADDI VM_REG(0x0), VM_CODE(0xa) [10, 20] | |
| 6: INT VM_CODE(0xb), 0x0 [1, 0] | |
| Interrupt: 1 | |
| 10 + 20 = 30 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment