Skip to content

Commit ca7d8a9

Browse files
committed
Make djnz instruction to return nz condition
Since djnz is dec b; jr nz, we signal this instruction uses nz. Note this has a slightly different semantic: For call, ret, jr, jp this is the condition under the instruction executes. For djnz, the instruction always does dec b, so it "partially executes". Also do some code cleanup to pass flake8 tests.
1 parent 697aa61 commit ca7d8a9

1 file changed

Lines changed: 7 additions & 3 deletions

File tree

arch/zx48k/optimizer/asm.py

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -135,17 +135,21 @@ def condition(asm):
135135
or None. E.g. 'c' for Carry, 'nz' for not-zero, etc.
136136
That is the condition required for this instruction
137137
to execute. For example: ADC A, 0 does NOT have a
138-
condition flag (it always execute) whilst RETC does.
138+
condition flag (it always execute) whilst RET C does.
139+
DJNZ has condition flag NZ
139140
"""
140141
i = Asm.inst(asm)
141142

142-
if i not in {'call', 'jp', 'jr', 'ret'}:
143+
if i not in {'call', 'jp', 'jr', 'ret', 'djnz'}:
143144
return None # This instruction always execute
144145

145146
if i == 'ret':
146147
asm = [x.lower() for x in asm.split(' ') if x != '']
147148
return asm[1] if len(asm) > 1 else None
148149

150+
if i == 'djnz':
151+
return 'nz'
152+
149153
asm = [x.strip() for x in asm.split(',')]
150154
asm = [x.lower() for x in asm[0].split(' ') if x != '']
151155
if len(asm) > 1 and asm[1] in {'c', 'nc', 'z', 'nz', 'po', 'pe', 'p', 'm'}:
@@ -208,7 +212,7 @@ def make_patt(mnemo):
208212
"""
209213
return r'^[ \t]*{}[ \t]*$'.format(RE_.sub('.+', re.escape(mnemo).replace(',', r',[ \t]*')))
210214

211-
RE_=re.compile(r'\bN+\b')
215+
RE_ = re.compile(r'\bN+\b')
212216
for mnemo, opcode_data in z80.Z80SET.items():
213217
pattern = make_patt(mnemo)
214218
Z80_PATTERN[re.compile(pattern, flags=re.IGNORECASE)] = opcode_data

0 commit comments

Comments
 (0)