Skip to content

Commit

Permalink
pointer logic instructions
Browse files Browse the repository at this point in the history
  • Loading branch information
MESYETI committed Nov 15, 2023
1 parent c787ac5 commit ca0a0b7
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 0 deletions.
10 changes: 10 additions & 0 deletions docs/architecture.md
Original file line number Diff line number Diff line change
Expand Up @@ -91,4 +91,14 @@ registers, words (16-bit) for data, and 24-bit values for addresses
- `WRBB (reg pair) (reg)` (0x31) - Writes the low 8-bits of `reg` to `BS` + reg pair
- `WRWB (reg pair) (reg)` (0x32) - Writes `reg` to `BS` + reg pair
- `WRAB (reg pair) (reg pair)` (0x33) - Writes the second reg pair to `BS` + second reg pair
- `LT (reg) (reg)` (0x34) - Sets `A` to 65535 if the first register is less than the
second register, and 0 if it isn't
- `GT (reg) (reg)` (0x35) - Sets `A` to 65535 if the first register is greater than the
second register, and 0 if it isn't
- `CMPP (reg pair) (reg pair)` (0x36) - Sets `A` to 65535 if the reg pairs are equal,
and 0 if they aren't
- `LTP (reg pair) (reg pair)` (0x37) - Sets `A` to 65535 if the first reg pair is less
than the second, and 0 if it isn't
- `GTP (reg pair) (reg pair)` (0x38) - Sets `A` to 65535 if the first reg pair is greater
than the second, and 0 if it isn't
- `HLT` (0xFF) - Stops execution
5 changes: 5 additions & 0 deletions source/assembler/assembler.d
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,11 @@ class Assembler {
AddInstruction("wrbb", Opcode.WRBB, [Param.RegisterPair, Param.Register]);
AddInstruction("wrwb", Opcode.WRWB, [Param.RegisterPair, Param.Register]);
AddInstruction("wrab", Opcode.WRAB, [Param.RegisterPair, Param.RegisterPair]);
AddInstruction("lt", Opcode.LT, [Param.Register, Param.Register]);
AddInstruction("gt", Opcode.GT, [Param.Register, Param.Register]);
AddInstruction("cmpp", Opcode.CMPP, [Param.RegisterPair, Param.RegisterPair]);
AddInstruction("gtp", Opcode.GTP, [Param.RegisterPair, Param.RegisterPair]);
AddInstruction("ltp", Opcode.LTP, [Param.RegisterPair, Param.RegisterPair]);
AddInstruction("hlt", Opcode.HLT, []);

// special
Expand Down
35 changes: 35 additions & 0 deletions source/computer.d
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,11 @@ enum Opcode {
WRBB = 0x31,
WRWB = 0x32,
WRAB = 0x33,
LT = 0x34,
GT = 0x35,
CMPP = 0x36,
LTP = 0x37,
GTP = 0x38,
HLT = 0xFF
}

Expand Down Expand Up @@ -696,6 +701,36 @@ class Computer {
WriteAddr(bs + addr, value);
break;
}
case Opcode.LT: {
auto v1 = ReadReg(NextByte());
auto v2 = ReadReg(NextByte());
a = v1 < v2? 0xFFFF : 0;
break;
}
case Opcode.GT: {
auto v1 = ReadReg(NextByte());
auto v2 = ReadReg(NextByte());
a = v1 > v2? 0xFFFF : 0;
break;
}
case Opcode.CMPP: {
auto v1 = ReadRegPair(NextByte());
auto v2 = ReadRegPair(NextByte());
a = v1 == v2? 0xFFFF : 0;
break;
}
case Opcode.LTP: {
auto v1 = ReadRegPair(NextByte());
auto v2 = ReadRegPair(NextByte());
a = v1 < v2? 0xFFFF : 0;
break;
}
case Opcode.GTP: {
auto v1 = ReadRegPair(NextByte());
auto v2 = ReadRegPair(NextByte());
a = v1 > v2? 0xFFFF : 0;
break;
}
case Opcode.HLT: {
halted = true;
break;
Expand Down

0 comments on commit ca0a0b7

Please sign in to comment.