Created
November 19, 2011 20:50
-
-
Save itsbth/1379339 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(9), | |
| /*3*/ INSTR_ADDI, VM_REG(0), VM_CODE(10), | |
| /*6*/ INSTR_INT, VM_CODE(11), 0, | |
| /*9*/ 10, 20, 1, | |
| /*c*/ 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; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment