Skip to content

Commit

Permalink
completed Minimal 64x4 example
Browse files Browse the repository at this point in the history
  • Loading branch information
michaelkamprath committed Apr 27, 2024
1 parent 2c9304a commit 8bdc21f
Show file tree
Hide file tree
Showing 4 changed files with 112 additions and 8 deletions.
28 changes: 23 additions & 5 deletions examples/slu4-minimal-64x4/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,31 @@ The following instruction macros have been added in the ISA configuration file f
| Macros Instruction | Operand 1 | Operand 2 | Description |
|:-:|:-:|:-:|:--|
| `spinit` | - | - | Init the stack popint to a value of `0xFFFE`. |
| `phsi` | 1 byte | - | Pushes a 1 byte immediate value onto the stack. |
| `phs2i` | 2 bytes | - | Pushes a 2 byte immediate value onto the stack. |
| `phs4i` | 4 bytes | - | Pushes a 4 byte immediate value onto the stack. |
| `phsptr` | 2 bytes | - | Pushes a 2 byte immediate absolute address onto the stack per the Min 64x4 calling convention. Similar to `phs2i` but the operand is validated as an address. |
| `phsi` | immediate | - | Pushes a 1 byte immediate byte onto the stack. |
| `phs2i` | immediate | - | Pushes a 2 byte immediate word onto the stack. |
| `phs4i` | immediate | - | Pushes a 4 byte immediate long onto the stack. |
| `phsptr` | abs address | - | Pushes a 2 byte immediate absolute address onto the stack per the Min 64x4 calling convention. Similar to `phs2i` but the operand is validated as an address. |
| `phs2s` | offset | - | Pushes a 2 byte word from the stack at the given offset onto stack |
| `phs4s` | offset | - | Pushes a 4 byte long from the stack at the given offset onto stack |
| `phsz` | zero page address | - | Pushes a 1 byte value from the zero page address onto the stack. |
| `phsv` | zero page address | - | Pushes a 2 byte word from the zero page address onto the stack. |
| `phsq` | zero page address | - | Pushes a 4 byte long from the zero page address onto the stack. |
| `pls2` | - | - | Pops a 2 byte value from the stack. |
| `pls4` | - | - | Pops a 4 byte value from the stack. |

| `mws2` | abs address | offset | Copies a 2 byte word from an absolute address to a specific offset on the stack. |
| `ms2w` | offset | abs address | Copies a 2 byte word from a specific offset on the stack to an absolute address. |
| `mvs2` | zero page address | offset | Copies a 2 byte word from a zero page address to a specific offset on the stack. |
| `ms2v` | offset | zero page address | Copies a 2 byte word from a specific offset on the stack to a zero page address. |
| `ms4q` | offset | zero page address | Copies a 4 byte long from a specific offset on the stack to a zero page address. |
| `mqs4` | zero page address | offset | Copies a 4 byte long from a zero page address to a specific offset on the stack. |
| `mls4` | abs address | offset | Copies a 4 byte long from an absolute address to a specific offset on the stack. |
| `ms4l` | offset | abs address | Copies a 4 byte long from a specific offset on the stack to an absolute address. |
| `aqq` | zero page address | zero page address | Adds two 4 byte longs from zero page addresses and stores the result in the second zero page address. |
| `sqq` | zero page address | zero page address | Subtracts the first 4 byte long at a zero page address from the second and stores the result in the second zero page address. |
| `mqq` | zero page address | zero page address | Copies a 4 byte long at the first zero page address to the 4 bytes at the second zero page address |
| `mll` | abs address | abs address | Copies a 4 byte long at the first absolute address to the 4 bytes at the second absolute address |
| `miq` | immediate | zero page address | Copies an immediate 4-byte long to a zero page long |
| `inq_` | zero page address | - | Increments a 4 byte long at a zero page address. Fixes the bug with the built-in `INQ` instruction as of v1.1.0 of the Minimal 64x4 OS. |

### Assembly Syntax
**BespokeASM**'s syntax is close to the syntax that Carsten used for the Minimal 64x4's assembly language. However, there are some differences:
Expand Down
86 changes: 86 additions & 0 deletions examples/slu4-minimal-64x4/slu4-minimal-64x4.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2757,6 +2757,29 @@ macros:
- "phs"
- "lds @ARG(0)+0+3"
- "phs"
phsz:
# push a zero-page byte to the stack
- operands:
count: 1
operand_sets:
list:
- zero_page
instructions:
- "ldz @ARG(0)"
- "phs"
phsv:
# push a zero-page word to the stack
# stack is arranged as big-endian, word in zero-page is little-endian
- operands:
count: 1
operand_sets:
list:
- zero_page
instructions:
- "ldz @ARG(0)+0"
- "phs"
- "ldz @ARG(0)+1"
- "phs"
phsq:
# push a zero page long to the stack
# stack is arranged as big-endian, long in zero-page is little-endian
Expand Down Expand Up @@ -2789,6 +2812,34 @@ macros:
- "pls"
- "pls"
- "pls"
mws2:
# move 2-byte word at absolute address to stack at offset
# stack is arranged as big-endian, word at abs address is little-endian
- operands:
count: 2
operand_sets:
list:
- absolute_address
- offset
instructions:
- "ldb @ARG(0)+0"
- "sts @ARG(1)+1"
- "ldb @ARG(0)+1"
- "sts @ARG(1)+0"
ms2w:
# move 2-byte word from stack at offset to absolute address
# stack is arranged as big-endian, word at abs address is little-endian
- operands:
count: 2
operand_sets:
list:
- offset
- absolute_address
instructions:
- "lds @ARG(0)+1"
- "stb @ARG(1)+0"
- "lds @ARG(0)+0"
- "stb @ARG(1)+1"
ms2v:
# move 2 bytes from stack to zero-page word
# stack is arranged as big-endian, word in zero-page is little-endian
Expand Down Expand Up @@ -2943,3 +2994,38 @@ macros:
- "mbb @ARG(0)+1,@ARG(1)+1"
- "mbb @ARG(0)+2,@ARG(1)+2"
- "mbb @ARG(0)+3,@ARG(1)+3"
mlq:
# move long from abs address to zero-page long
- operands:
count: 2
operand_sets:
list:
- absolute_address
- zero_page
instructions:
- "mwv @ARG(0)+0,@ARG(1)+0"
- "mwv @ARG(0)+2,@ARG(1)+2"
miq:
# move 4 bytes long from immediate to zero-page long
- operands:
count: 2
operand_sets:
list:
- immediate_16bit
- zero_page
instructions:
- "miv @ARG(0) & $0000FFFF ,@ARG(1)+0"
- "miv (@ARG(0) & $FFFF0000) >> 16,@ARG(1)+2"
inq_:
# increment zero-page long. This macro exists because the built-in instruction INQ has a bug.
- operands:
count: 1
operand_sets:
list:
- zero_page
instructions:
- "inv @ARG(0)+0"
- "ldi 0"
- "ac.z @ARG(0)+2"
- "ldi 0"
- "ac.z @ARG(0)+3"
1 change: 1 addition & 0 deletions examples/slu4-minimal-64x4/software/mathlib32.min64x4
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ _counter: .byte 0
; Returns
; flags will be set per comparison
;
.align
compare_uint32ss:
; load values into zero page and then use _compare_uint32_XY
ms4q 7,_argX4
Expand Down
5 changes: 2 additions & 3 deletions examples/slu4-minimal-64x4/software/primes.min64x4
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,7 @@ _n_value: .zero 4
.org 0 "USER_APPS"
start:
; init N-value to 1
clq _n_value
miz 1,_n_value+0
miq 1,_n_value+0
.n_loop:
phsi 0
phsq _n_value
Expand All @@ -28,7 +27,7 @@ start:
phsptr is_prime_str jps _PrintPtr pls2
; jps _WaitInput
.increment_n:
inq _n_value
inq_ _n_value
jpa .n_loop

is_prime_str: .cstr " is prime!\n"
Expand Down

0 comments on commit 8bdc21f

Please sign in to comment.