Skip to content

Commit a5f1e43

Browse files
committed
Add new IC instruction to declare local arrays
LVARD declares local arrays.
1 parent 4d5267d commit a5f1e43

1 file changed

Lines changed: 39 additions & 1 deletion

File tree

arch/zx48k/backend/__init__.py

Lines changed: 39 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -579,6 +579,44 @@ def _lvard(ins):
579579
return output
580580

581581

582+
def _larrd(ins):
583+
""" Defines a local array.
584+
- 1st param is offset of the local variable.
585+
- 2nd param is a list of bytes in hexadecimal corresponding to the index table
586+
- 3rd param is the size of elements in byte
587+
- 4rd param a list (might be empty) of byte to initialize the array with
588+
"""
589+
output = []
590+
591+
label = tmp_label()
592+
offset = int(ins.quad[1])
593+
elements_size = ins.quad[3]
594+
AT_END.extend(_vard(Quad('vard', label, ins.quad[2])))
595+
must_initialize = ins.quad[4] != '[]'
596+
597+
if must_initialize:
598+
label2 = tmp_label()
599+
AT_END.extend(_vard(Quad('vard', label2, ins.quad[4])))
600+
output.extend([
601+
'ld hl, %s' % label2,
602+
'push hl'
603+
])
604+
605+
output.extend([
606+
'ld hl, %i' % -offset,
607+
'ld de, %s' % label,
608+
'ld bc, %s' % elements_size,
609+
])
610+
611+
if must_initialize:
612+
output.append('call __ALLOC_INITIALIZED_LOCAL_ARRAY')
613+
else:
614+
output.append('call __ALLOC_LOCAL_ARRAY')
615+
616+
REQUIRES.add('arrayalloc.asm')
617+
return output
618+
619+
582620
def _out(ins):
583621
""" Translates OUT to asm.
584622
"""
@@ -2099,7 +2137,7 @@ def __str__(self):
20992137
'vard': [2, _vard], # Like the above but with a list of items (chars, bytes or words, hex)
21002138
'lvarx': [3, _lvarx], # Initializes a local variable. lvard X, (list of bytes): Initializes variable at offset X
21012139
'lvard': [2, _lvard], # Initializes a local variable. lvard X, (list of bytes): Initializes variable at offset X
2102-
2140+
'larrd': [4, _larrd], # Initializes a local array
21032141
'memcopy': [3, _memcopy], # Copies a block of param 3 bytes of memory from param 2 addr to param 1 addr.
21042142

21052143
'bandu8': [3, _band8], # x = A & B

0 commit comments

Comments
 (0)