-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinfile
More file actions
175 lines (142 loc) · 2.52 KB
/
Copy pathinfile
File metadata and controls
175 lines (142 loc) · 2.52 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
ldi ax,0
ldi bx,10
str ax,bx
inc ax
push bx
ldi bx,24
cmp ax,bx
pop bx
je 1
jmp -8
ldi bx,0
str ax,bx
dec ax
push bx
ldi bx,0
cmp ax,bx
pop bx
je 1
jmp -8
jmp -20
0
######### Stack Testing
ldi ax,1
ldi bx,10
push ax
inc ax
cmp ax,bx
je 1
jmp -5
0
########### Test Programs ########
- Count to 5 and back to 0
- Repeat
ldi ax,0
ldi bx,5
inc ax
cmp ax,bx
je 1
jmp -4
ldi bx,0
dec ax
cmp ax,bx
je -9
jmp -4
0
######
- Fill Memory up
# Will Crash the CPU!
# WARNING: No bounds checking for memory
# Will throw an error in python, the CPU is functioning as expected
ldi ax,0
ldi bx,99
str ax,bx
inc ax
jmp -3
0
# This version won't crash the CPU
# Uses the Stack
ldi ax,0
ldi bx,99
str ax,bx
inc ax
push bx
ldi bx,4
cmp ax,bx
je 2
pop bx
jmp -8
0
#Fill Memory with Stack
ldi ax,1
ldi bx,5
push ax
inc ax
cmp ax,bx
je 1
jmp -5
0
#####
- Fill with 1's and then empty the memory, loop
- Fixed, pops and pushes didn't line up ;-)
- Run with sleep(0.01), oooh aaaah
ldi ax,0
ldi bx,10
str ax,bx
inc ax
push bx
ldi bx,24
cmp ax,bx
pop bx
je 1
jmp -8
ldi bx,0
str ax,bx
dec ax
push bx
ldi bx,0
cmp ax,bx
pop bx
je 1
jmp -8
jmp -20
0
######
Notation Rules:
1. Do the Notes
2. Compiler will tolerate spaces in the Code
-- If you want in-line notes use a space after the instructions and with #
eg. add ax,bx #Notes like This
- In-line is OK!
add ax,bx
#Note here, include the "#" mark before the notes
cmp ax,bx
jmp -3 #Spaces are OK!
0
You can put notes after '0' in ANY way you like
- Compiler and CPU will NOT process any instructions after "0"
- NOP WILL work however you need a 0 next to it
nop 0 <-- include the Zero
#Bug in how the Instruction Splitting is handled (Low Priority)
----- IMPORTANT: How JMP instruction is calculated -----
Jumping is Relative to the point from which you jmp
- For NEGATIVE Jumping (Back/Up)
inc ax,0 <-- jumps here jmp -3
inc bx,0 <-------------- jmp -2
jmp -3 <-------------- jmp -1
0 - Halts CPU & Compiler!
- For POSITIVE Jumping (Forward/Down)
jmp 1 - Skips
inc ax <----- jmp 0
inc ax <----- jmp 1
inc ax <----- jmp 2
inc ax <----- jmp 3
0
#Not a bug, Expected Behavior
####################
Code Notes:
Adjust the Speed of the CPU using the SLEEP instruction in the Python Code
- Not recommended to use sleep for anything more than 10 khz (0.0001) as it WILL BOG DOWN YOUR CPU
---->>>> This is because it is outputting to the Console
---->>>> Comment out the bottom print lines at the end of cpu.py for more performance
---->>>> You can remove the sleep() line and it will Freewheel the CPU