A cross-platform simulator for the GreenArrays GA144 multi-computer chip.
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

Implement `if` and `-if` opcodes

+45 -2
+45 -2
src/opcodes.zig
··· 69 69 call, 70 70 unext, 71 71 next, 72 - nop, 73 - nop, 72 + _if, 73 + minus_if, 74 74 fetchP, 75 75 fetchPlus, 76 76 fetchB, ··· 226 226 try expectEqual(0x122, computer.return_stack.t); 227 227 computer.step(); 228 228 try expectEqual(0x22, computer.p.address.local); 229 + } 230 + 231 + /// if 232 + /// 233 + /// **If**. If T is nonzero, continues with the next instruction word addressed by P. If T is zero, jumps 234 + pub fn _if(self: *Computer) void { 235 + if (self.data_stack.t == 0) { 236 + self.p.jump(self.slot, self.i); 237 + } 238 + } 239 + 240 + test _if { 241 + var computer: Computer = .reset; 242 + computer.i = @bitCast(f18.Jump{ .destination = 0x44 }); 243 + computer.slot = 1; 244 + computer.data_stack.t = 0; 245 + 246 + _if(&computer); 247 + try expectEqual(0x44, computer.p.address.local); 248 + computer.step(); 249 + try expectEqual(0, computer.p.address.local); 250 + } 251 + 252 + /// -if 253 + /// 254 + /// Minus-if. If T is negative (T17 set), continues with the next instruction 255 + /// word addressed by P. If T is positive, jumps 256 + pub fn minus_if(self: *Computer) void { 257 + if (self.data_stack.t >= 0) { 258 + self.p.jump(self.slot, self.i); 259 + } 260 + } 261 + 262 + test minus_if { 263 + var computer: Computer = .reset; 264 + computer.i = @bitCast(f18.Jump{ .destination = 0x44 }); 265 + computer.slot = 1; 266 + computer.data_stack.t = 1; 267 + 268 + minus_if(&computer); 269 + try expectEqual(0x44, computer.p.address.local); 270 + computer.step(); 271 + try expectEqual(0, computer.p.address.local); 229 272 } 230 273 231 274 /// @p