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.

Another attempt at extended arithmetic

+29 -3
+5
src/f18.zig
··· 120 120 return_stack: stack.ReturnStack, 121 121 data_stack: stack.DataStack, 122 122 123 + carry: u1, 124 + 123 125 state: State = .fetch, 124 126 125 127 slot: u2, ··· 219 221 220 222 .return_stack = .empty, 221 223 .data_stack = .empty, 224 + 225 + .carry = 0, 222 226 223 227 .mem = [_]Word{0} ** 128, 224 228 ··· 373 377 try expectEqual(0, computer.i); 374 378 try expectEqual(stack.ReturnStack.empty, computer.return_stack); 375 379 try expectEqual(stack.DataStack.empty, computer.data_stack); 380 + try expectEqual(0, computer.carry); 376 381 try expectEqual(.fetch, computer.state); 377 382 try expectEqual([_]Word{0} ** 128, computer.mem); 378 383 }
+24 -3
src/opcodes.zig
··· 468 468 /// + 469 469 /// 470 470 /// **Plus**. Replaces T with the twos complement sum of S and T. Pops data stack into S. This instruction is affected in Extended Arithmetic Mode, becoming **Add with carry**. Includes the latched carry in the sum, and latches the carry out from bit 17. 471 - /// TODO: handle add with carry 472 471 pub fn add(self: *Computer) void { 473 - const result, const overflow = @addWithOverflow(self.data_stack.s, self.data_stack.pop()); 474 - _ = overflow; 472 + var result: f18.Word = 0; 473 + if (self.p.extended_arithmetic) { 474 + result, self.carry = @addWithOverflow(self.data_stack.s + self.carry, self.data_stack.pop()); 475 + } else { 476 + result = self.data_stack.s + self.data_stack.pop(); 477 + } 475 478 self.data_stack.push(result); 476 479 } 477 480 ··· 482 485 483 486 add(&computer); 484 487 try expectEqual(0x579, computer.data_stack.t); 488 + } 489 + 490 + test "add in extended_arithmetic mode" { 491 + var computer: Computer = .reset; 492 + computer.p.extended_arithmetic = true; 493 + computer.data_stack.push(0x123); 494 + computer.data_stack.push(0x456); 495 + 496 + add(&computer); 497 + try expectEqual(0x579, computer.data_stack.t); 498 + try expectEqual(0, computer.carry); 499 + 500 + computer.data_stack.push(0x1ffff); 501 + computer.data_stack.push(0x1ffff); 502 + 503 + add(&computer); 504 + try expectEqual(-2, computer.data_stack.t); 505 + try expectEqual(1, computer.carry); 485 506 } 486 507 487 508 /// and