Added new instructions.

Added CCF - Clear Carry Flag
Added BRC - Branch on Carry Flag
Improved CALL and RET - All registers but status now saved and restored.
This commit is contained in:
Anachronaut
2024-10-29 21:04:03 -04:00
committed by GitHub
parent f9308338c4
commit a58fb3d694
8 changed files with 255 additions and 112 deletions
+28 -38
View File
@@ -29,17 +29,18 @@ Hex Code | Mnemonic | Description
07 | NOTA | Bitwise inversion of A, the result is stored in Q.
08 | NOTB | Bitwise inversion of B, the result is stored in Q.
### Branch Operations: 4 Instructions
### Branch Operations: 7 Instructions
Hex Code | Mnemonic | Description
-- | -- | --
10 | BRI | Branch Immediately. Loads the immediate next two bytes of Program Memory into the Program Counter, first the most significant byte, then the least.
11 | BRQ | Branch on Q. If Q is zero, loads the immediate next two bytes of Program Memory into the Program Counter.
12 | BRA | Branch on A. If A is zero, loads the immediate next two bytes of Program Memory into the Program Counter.
13 | BRB | Branch on B. If B is zero, loads the immediate next two bytes of Program Memory into the Program Counter.
14 | CALL | Push the Program Counter to the Stack, loads the immediate next two bytes of Program Memory into the Program Counter.
15 | RET | Restores the Program Counter from the Stack, used to return from subroutines.
14 | CALL | Stores all the registers to the Stack, A, B, Q, the Data Pointer, and the Program Counter, then performs an immediate branch.
15 | RET | Restores all registers from the Stack, then immediately branches to the Return Address by setting the Program Counter to the next instruction after the last CALL.
16 | BRC | Branch if Carry is set.
### Register Operations: 6 Instructions
### Register Operations: 11 Instructions
| Hex Code | Mnemonic | Description |
| -------- | -------- | ------------------- |
| 20 | RSTA | Resets A to 0. |
@@ -52,8 +53,9 @@ Hex Code | Mnemonic | Description
| 27 | LDB | Loads Data to B via the Data Pointer.
| 28 | INIA | Loads the next byte of Program Memory to A. |
| 29 | INIB | Loads the next byte of Program Memory to B. |
| 2F | CCF | Clears the Carry Flag. |
### Stack Operations: 9 Instructions
### Stack Operations: 7 Instructions
Hex Code | Mnemonic | Description
-- | -- | --
30 | PSHQ | Stores Q into Data Memory at the location referenced by the Stack Pointer then decrements the Stack Pointer.
@@ -64,7 +66,7 @@ Hex Code | Mnemonic | Description
35 | POPB | Reads the location referenced by the Stack Pointer from Data Memory into B then increments the Stack Pointer.
36 | POPD | Restores the Program Counter from the top two bytes in the stack, increments the Stack Pointer by two.
### Data Operations: 7 Instructions
### Data Operations: 8 Instructions
Hex Code | Mnemonic | Description
-- | -- | --
40 | INCD | Increments the Data Pointer.
@@ -103,38 +105,26 @@ The current implementation has Input 0 and Output 0 hooked to stdout and stdin r
### Example Program: Hello World
```
; Hello World for SplitBit CPU
; First, we define the string in Data Memory.
Data:
0000 0x48 ; 'H'
0001 0x65 ; 'e'
0002 0x6C ; 'l'
0003 0x6C ; 'l'
0004 0x6F ; 'o'
0005 0x2C ; ','
0006 0x20 ; ' '
0007 0x57 ; 'W'
0008 0x6F ; 'o'
0009 0x72 ; 'r'
000A 0x6C ; 'l'
000B 0x64 ; 'd'
000C 0x32 ; '!'
000D 0x0A ; This is a linefeed, it's equivalent to putting '\n' in a string in C.
000E 0x00 ; Zero terminates the string.
; This is a basic hello world program for the SplitBit CPU.
; We'll create a loop that outputs each byte of our string to Output 0, the text console.
; Next, we'll create a loop that outputs each byte of our string to Output 0, the text console.
Program:
0000 LDA 0x42 ; Load the first byte of the string into A.
0001 BRA 0x12 ; If A is zero, branch out of the loop.
0002 0x00 0x00 ; The high byte of the branch.
0003 0x0A 0x0A ; The low byte of the branch.
0004 OUTA 0xD1 ; Output the value in A.
0005 0x01 0x00 ; The Output Port to use.
0006 INCD 0x40 ; Increment the Data Pointer to the next byte of the string.
0007 BRI 0x10 ; Branch immediately to the start of the loop.
0008 0x00 0x00 ; The high byte of the branch address.
0009 0x00 0x00 ; The low byte of the branch address.
000A HALT 0xFF ; The end of the program.
#Program
Start:
LDA ; Load a byte of the string into A.
BRA End ; If A is zero, branch out of the loop.
OUTA 0x00 ; Output the value in A to Port 0, the text console.
INCD ; Increment the Data Pointer to the next byte of the string.
BRI Start ; Branch immediately to the start of the loop.
End:
INIA 0x0A ; We'll load a linefeed into A and output it to make it look nice.
OUTA 0x00 ; Output it to the text console.
HALT ; Terminate the program.
#Data
"Hello, World!"
```
### Structure of a SplitBit Binary File:
@@ -143,5 +133,5 @@ The Program and Data values are both stored in a single file for loading into th
Here's an example hex dump of the hello world program stored in the proper format:
```
50 52 47 00 0A 42 12 00 0A D1 00 40 10 00 00 FF 44 41 54 00 0E 48 65 6C 6C 6F 2C 20 57 6F 72 6C 64 21 0A 00
50 52 47 00 0F 26 12 00 0A D1 00 40 10 00 00 28 0A D1 00 FF 44 41 54 00 0E 48 65 6C 6C 6F 2C 20 57 6F 72 6C 64 21 00
```