You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
// "The opcode is a two-digit number based only on the ones and tens digit of the value, that is, the opcode is the rightmost two digits of the first value in an instruction"
172
175
letop=this.OPS[temp_op.substr(-2,2)];
173
176
177
+
if(!op){
178
+
debugger;
179
+
}
180
+
174
181
letfull_op=temp_op.padStart(op.params+2,'0');
175
182
176
-
letmodes=[];
183
+
letmodes=this.sharedModes;
177
184
178
185
// "Parameter modes are single digits, one per parameter, read **right-to-left** from the opcode"
179
186
for(leti=op.params-1;i>=0;i--){
180
-
modes.push(full_op[i]);
187
+
// [0,1,2,3,4,5]
188
+
// ^ ops.params = 6
189
+
// 5 -> 0 # |(5 - 6 + 1)| = | 0| = 0
190
+
// 4 -> 1 # |(4 - 6 + 1)| = |-1| = 1
191
+
// 3 -> 2 # |(3 - 6 + 1)| = |-2| = 2
192
+
// 2 -> 3 # |(2 - 6 + 1)| = |-3| = 3
193
+
// 1 -> 4 # |(1 - 6 + 1)| = |-4| = 4
194
+
// 0 -> 5 # |(0 - 6 + 1)| = |-5| = 5
195
+
modes[Math.abs(i-op.params+1)]=full_op[i];
181
196
}
182
197
183
198
letrtn_obj={
@@ -189,10 +204,10 @@ class Computer {
189
204
returnrtn_obj;
190
205
}
191
206
192
-
runOp({ modes, fn, jumps, write }){
207
+
runOp({ modes,params,fn, jumps, write }){
193
208
this.pointer++;
194
209
letvalues=[];
195
-
for(leti=0;i<modes.length;i++){
210
+
for(leti=0;i<params;i++){
196
211
letmode=modes[i];
197
212
letvalue=this.memory[this.pointer+i];
198
213
@@ -262,7 +277,7 @@ class Computer {
262
277
* - I am running an op that does _not_ write to memory
263
278
* - Or if I am not at the last parameter in the op
0 commit comments