Skip to content

Commit

Permalink
add CALLB
Browse files Browse the repository at this point in the history
  • Loading branch information
MESYETI committed Nov 19, 2023
1 parent b636787 commit 97e4fe2
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 1 deletion.
1 change: 1 addition & 0 deletions docs/architecture.md
Original file line number Diff line number Diff line change
Expand Up @@ -104,4 +104,5 @@ registers, words (16-bit) for data, and 24-bit values for addresses
- `PUSHA (reg pair)` (0x39) - Pushes the given register pair to the stack
- `POPA (reg pair)` (0x3A) - Pops a register pair from the stack and stores it in the
given register pair
- `CALLB (addr)` (0x3B) - Pushes IP to the stack and jumps to `BS` + addr
- `HLT` (0xFF) - Stops execution
3 changes: 2 additions & 1 deletion source/assembler/assembler.d
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,8 @@ class Assembler {
AddInstruction("ltp", Opcode.LTP, [Param.RegisterPair, Param.RegisterPair]);
AddInstruction("pusha", Opcode.PUSHA, [Param.RegisterPair]);
AddInstruction("popa", Opcode.POPA, [Param.RegisterPair]);
AddInstruction("hlt", Opcode.HLT, []);
AddInstruction("callb", Opcode.CALLB, [Param.Addr]);
AddInstruction("hlt", Opcode.HLT, []);

// special
AddInstruction("db", Param.Byte);
Expand Down
9 changes: 9 additions & 0 deletions source/computer.d
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ enum Opcode {
GTP = 0x38,
PUSHA = 0x39,
POPA = 0x3A,
CALLB = 0x3B,
HLT = 0xFF
}

Expand Down Expand Up @@ -753,6 +754,14 @@ class Computer {
WriteRegPair(NextByte(), ReadAddr(sp));
break;
}
case Opcode.CALLB: {
auto addr = NextAddr();

WriteAddr(sp, ip);
sp += 3;
ip = bs + addr;
break;
}
case Opcode.HLT: {
halted = true;
break;
Expand Down

0 comments on commit 97e4fe2

Please sign in to comment.