Test case showing difference between local and global arrays

This commit is contained in:
2025-09-04 11:51:39 +00:00
parent 59845b283b
commit 5e51159367
2 changed files with 37 additions and 0 deletions

7
Makefile Normal file
View File

@@ -0,0 +1,7 @@
array.tap: array.bas
zxbc -o $@ -f tap -B -a $<
clean:
rm -f array.tap
.PHONY: clean

30
array.bas Normal file
View File

@@ -0,0 +1,30 @@
DIM global(5) AS UByte => { 47h, 4Ch, 4Fh, 42h, 41h, 4Ch }
subroutine()
STOP
SUB subroutine()
DIM local(4) AS UByte => { 4Ch, 4Fh, 43h, 41h, 4Ch }
refer(6, @global)
refer(5, @local)
END SUB
SUB refer(chars AS UByte, pointer AS UInteger)
DIM i AS UByte
REM Are we pointing to .array.__DATA__ ?
PRINT "If reference points to the DATA field ("; pointer;"): ";
FOR i = 0 TO chars - 1
PRINT CHR$(PEEK (pointer + i));" ";
NEXT i
PRINT
REM Are we pointing to .array, where pointer + 2 = data pointer?
pointer = PEEK(pointer + 2) + 256 * PEEK(pointer + 3)
PRINT "If reference points to pointer field ("; pointer;"): ";
FOR i = 0 TO chars - 1
PRINT CHR$(PEEK (pointer + i));" ";
NEXT i
PRINT
END SUB
37568