New SplitBit programs.
This commit is contained in:
@@ -0,0 +1,54 @@
|
||||
; Tests the Data Pointer calling convention.
|
||||
;
|
||||
; Every Data Pointer is aimed at a different marker byte, then a subroutine
|
||||
; repoints all four of them at Z and returns.
|
||||
;
|
||||
; DP0 through DP2 are preserved across a CALL, so they should come back still
|
||||
; aimed at their own markers. DP3 is volatile, which is what lets a subroutine
|
||||
; hand an address back to its caller, so it should come back aimed at Z.
|
||||
;
|
||||
; Correct output is ABCZ.
|
||||
|
||||
#Program
|
||||
|
||||
start:
|
||||
SETD.0 MarkA
|
||||
SETD.1 MarkB
|
||||
SETD.2 MarkC
|
||||
SETD.3 MarkD
|
||||
CALL clobber
|
||||
|
||||
; Read a byte through each pointer in turn and print it.
|
||||
LDA.0
|
||||
OUTA 0x00
|
||||
LDA.1
|
||||
OUTA 0x00
|
||||
LDA.2
|
||||
OUTA 0x00
|
||||
LDA.3
|
||||
OUTA 0x00
|
||||
|
||||
INIA 0x0A
|
||||
OUTA 0x00
|
||||
HALT
|
||||
|
||||
clobber:
|
||||
; Aim every pointer somewhere else. Only the change to DP3 should outlive the RET.
|
||||
SETD.0 MarkZ
|
||||
SETD.1 MarkZ
|
||||
SETD.2 MarkZ
|
||||
SETD.3 MarkZ
|
||||
RET
|
||||
|
||||
#Data
|
||||
|
||||
MarkA:
|
||||
"A"
|
||||
MarkB:
|
||||
"B"
|
||||
MarkC:
|
||||
"C"
|
||||
MarkD:
|
||||
"D"
|
||||
MarkZ:
|
||||
"Z"
|
||||
@@ -0,0 +1,46 @@
|
||||
; Copies a string from one place in Data Memory to another, reading through DP0
|
||||
; and writing through DP1 at the same time.
|
||||
;
|
||||
; On a machine with one Data Pointer this loop needs a PSHD and a POPD on every
|
||||
; pass to swap the pointer between the two regions. With two pointers it is just
|
||||
; a load and a store.
|
||||
;
|
||||
; It also checks that a bare mnemonic still means DP0.
|
||||
|
||||
#Program
|
||||
|
||||
start:
|
||||
SETD.0 Source ; DP0 walks the source.
|
||||
SETD.1 Dest ; DP1 walks the destination.
|
||||
|
||||
copy:
|
||||
LDA.0 ; Read a byte through DP0.
|
||||
BRA copyDone ; A zero byte is the end of the string.
|
||||
STA.1 ; Write it through DP1.
|
||||
INCD.0
|
||||
INCD.1
|
||||
BRI copy
|
||||
|
||||
copyDone:
|
||||
SETD Dest ; No selector, so this is DP0.
|
||||
print:
|
||||
LDA
|
||||
BRA end
|
||||
OUTA 0x00
|
||||
INCD
|
||||
BRI print
|
||||
|
||||
end:
|
||||
INIA 0x0A
|
||||
OUTA 0x00
|
||||
HALT
|
||||
|
||||
#Data
|
||||
|
||||
Source:
|
||||
"Two pointers, no stack shenanigans."
|
||||
|
||||
Dest:
|
||||
0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00
|
||||
0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00
|
||||
0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00
|
||||
Reference in New Issue
Block a user