Commit 0f27ef741adbeedf85960affad573404da6a2a9d
0 parents
Initial code
Showing
14 changed files
with
199 additions
and
0 deletions
.gitignore
0 → 100644
.idea/misc.xml
0 → 100644
1 | +++ a/.idea/misc.xml | |
1 | +<?xml version="1.0" encoding="UTF-8"?> | |
2 | +<project version="4"> | |
3 | + <component name="CMakeWorkspace" PROJECT_DIR="$PROJECT_DIR$" /> | |
4 | + <component name="ProjectLevelVcsManager" settingsEditedManually="false"> | |
5 | + <OptionsSetting value="true" id="Add" /> | |
6 | + <OptionsSetting value="true" id="Remove" /> | |
7 | + <OptionsSetting value="true" id="Checkout" /> | |
8 | + <OptionsSetting value="true" id="Update" /> | |
9 | + <OptionsSetting value="true" id="Status" /> | |
10 | + <OptionsSetting value="true" id="Edit" /> | |
11 | + <ConfirmationsSetting value="0" id="Add" /> | |
12 | + <ConfirmationsSetting value="0" id="Remove" /> | |
13 | + </component> | |
14 | +</project> | |
0 | 15 | \ No newline at end of file | ... | ... |
.idea/modules.xml
0 → 100644
1 | +++ a/.idea/modules.xml | |
1 | +<?xml version="1.0" encoding="UTF-8"?> | |
2 | +<project version="4"> | |
3 | + <component name="ProjectModuleManager"> | |
4 | + <modules> | |
5 | + <module fileurl="file://$PROJECT_DIR$/.idea/synacorvm.iml" filepath="$PROJECT_DIR$/.idea/synacorvm.iml" /> | |
6 | + </modules> | |
7 | + </component> | |
8 | +</project> | |
0 | 9 | \ No newline at end of file | ... | ... |
.idea/synacorvm.iml
0 → 100644
1 | +++ a/.idea/synacorvm.iml | |
1 | +<?xml version="1.0" encoding="UTF-8"?> | |
2 | +<module type="CPP_MODULE" version="4"> | |
3 | + <component name="NewModuleRootManager"> | |
4 | + <content url="file://$MODULE_DIR$"> | |
5 | + <sourceFolder url="file://$MODULE_DIR$/cpu.h" isTestSource="false" /> | |
6 | + <sourceFolder url="file://$MODULE_DIR$/CMakeLists.txt" isTestSource="false" /> | |
7 | + <sourceFolder url="file://$MODULE_DIR$/binary_decoder.c" isTestSource="false" /> | |
8 | + <sourceFolder url="file://$MODULE_DIR$/stack.c" isTestSource="false" /> | |
9 | + <sourceFolder url="file://$MODULE_DIR$/mem.h" isTestSource="false" /> | |
10 | + <sourceFolder url="file://$MODULE_DIR$/main.c" isTestSource="false" /> | |
11 | + <sourceFolder url="file://$MODULE_DIR$/cpu.c" isTestSource="false" /> | |
12 | + <sourceFolder url="file://$MODULE_DIR$/registers.h" isTestSource="false" /> | |
13 | + <sourceFolder url="file://$MODULE_DIR$/binary_decoder.h" isTestSource="false" /> | |
14 | + <sourceFolder url="file://$MODULE_DIR$/stack.h" isTestSource="false" /> | |
15 | + </content> | |
16 | + <orderEntry type="sourceFolder" forTests="false" /> | |
17 | + <orderEntry type="module-library"> | |
18 | + <library name="Header Search Paths"> | |
19 | + <CLASSES> | |
20 | + <root url="file:///usr/lib/gcc/x86_64-linux-gnu/6/include-fixed" /> | |
21 | + <root url="file:///usr/lib/gcc/x86_64-linux-gnu/6/include" /> | |
22 | + <root url="file:///usr/include" /> | |
23 | + <root url="file:///usr/local/include" /> | |
24 | + </CLASSES> | |
25 | + <SOURCES> | |
26 | + <root url="file:///usr/lib/gcc/x86_64-linux-gnu/6/include-fixed" /> | |
27 | + <root url="file:///usr/lib/gcc/x86_64-linux-gnu/6/include" /> | |
28 | + <root url="file:///usr/include" /> | |
29 | + <root url="file:///usr/local/include" /> | |
30 | + </SOURCES> | |
31 | + </library> | |
32 | + </orderEntry> | |
33 | + </component> | |
34 | +</module> | |
0 | 35 | \ No newline at end of file | ... | ... |
CMakeLists.txt
0 → 100644
1 | +++ a/CMakeLists.txt | |
1 | +cmake_minimum_required(VERSION 3.5) | |
2 | +project(synacorvm) | |
3 | + | |
4 | +set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11") | |
5 | + | |
6 | +set(SOURCE_FILES main.c cpu.c cpu.h binary_decoder.c binary_decoder.h registers.h mem.h stack.c stack.h) | |
7 | +add_executable(synacorvm ${SOURCE_FILES}) | |
0 | 8 | \ No newline at end of file | ... | ... |
binary_decoder.c
0 → 100644
binary_decoder.h
0 → 100644
cpu.c
0 → 100644
cpu.h
0 → 100644
main.c
0 → 100644
mem.h
0 → 100644
registers.h
0 → 100644
1 | +++ a/registers.h | |
1 | +// | |
2 | +// Created by imanol on 12/25/16. | |
3 | +// | |
4 | + | |
5 | +#ifndef SYNACORVM_REGISTERS_H | |
6 | +#define SYNACORVM_REGISTERS_H | |
7 | + | |
8 | +short r0 = 0; | |
9 | +short r1 = 0; | |
10 | +short r2 = 0; | |
11 | +short r3 = 0; | |
12 | +short r4 = 0; | |
13 | +short r5 = 0; | |
14 | +short r6 = 0; | |
15 | +short r7 = 0; | |
16 | + | |
17 | +short pc = 0; | |
18 | + | |
19 | +#endif //SYNACORVM_REGISTERS_H | ... | ... |
stack.c
0 → 100644
1 | +++ a/stack.c | |
1 | +// | |
2 | +// Created by imanol on 12/25/16. | |
3 | +// | |
4 | + | |
5 | +#include <malloc.h> | |
6 | +#include "stack.h" | |
7 | + | |
8 | +#define EXTEND_SIZE 10 | |
9 | + | |
10 | +uint32_t stack_size = EXTEND_SIZE; | |
11 | +uint32_t stack_pos = 0; | |
12 | +short *stack; | |
13 | + | |
14 | +void initialize_stack() | |
15 | +{ | |
16 | + stack = calloc(EXTEND_SIZE,sizeof(short)); | |
17 | +} | |
18 | + | |
19 | +void extend_stack() | |
20 | +{ | |
21 | + stack_size += EXTEND_SIZE; | |
22 | + realloc(stack,stack_size*sizeof(short)); | |
23 | +} | |
24 | + | |
25 | +void shrink_stack() | |
26 | +{ | |
27 | + stack_size -= EXTEND_SIZE; | |
28 | + realloc(stack,stack_size*sizeof(short)); | |
29 | +} | |
30 | + | |
31 | +void push(short value) | |
32 | +{ | |
33 | + stack[stack_pos++] = value; | |
34 | + if(stack_pos == stack_size-1) | |
35 | + { | |
36 | + extend_stack(); | |
37 | + } | |
38 | +} | |
39 | +short pop() | |
40 | +{ | |
41 | + short value = stack[stack_pos--]; | |
42 | + if(stack_size - stack_pos == 2*EXTEND_SIZE) | |
43 | + { | |
44 | + shrink_stack(); | |
45 | + } | |
46 | + return value; | |
47 | +} | |
0 | 48 | \ No newline at end of file | ... | ... |
stack.h
0 → 100644