This repository has been archived by the owner on Aug 30, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
I8080_M0Plus_Mappings.py
241 lines (227 loc) · 6.66 KB
/
I8080_M0Plus_Mappings.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
# Intel 8080 translation mapping for M0Plus
# The mapping provided is FROM Intel 8080 instructions TO ARM M0+ instructions.
# Each key in the dictionary represents an Intel 8080 instruction.
# Its corresponding value represents the ARM M0+ instruction(s) it should be translated to.
mapping_misc_control = {
"NOP": "NOP",
"HLT": "NOP", # Placeholder for HLT instruction
"RIM": "NOP", # Placeholder for RIM instruction
"SIM": "NOP", # Placeholder for SIM instruction
"EI": "CPSIE i", # Enable interrupts
"DI": "CPSID i", # Disable interrupts
"PCHL": "MOV PC, HL",
"SPHL": "MOV SP, HL",
"LHLD": "LDR HL, [ADR]",
"SHLD": "STR HL, [ADR]",
"XTHL": "LDR R3, [SP], MOV R2, SP, STR R2, [HL], MOV SP, R3",
"XCHG": "MOV R2, HL, MOV HL, DE, MOV DE, R2"
}
mapping_jumps_calls = {
"JMP": "B",
"JC": "BCS",
"JNC": "BCC",
"JM": "BMI",
"JZ": "BEQ",
"JNZ": "BNE",
"JP": "B", # Placeholder for Branch instruction
# "JP": "BPL", It should be noted here, that many instructions depend on following instructions.
#
"CALL": "BL",
"CC": "BCS",
"CNC": "BCC",
"CP": "BPL",
"CM": "BMI",
"CZ": "BEQ",
"CNZ": "BNE",
}
mapping_8bit_load_store_move = {
"MOV": "MOV",
"MVI": "MOV",
"SPHL": "MOV SP, HL",
"LDA": "LDR A, [ADR]",
"LXI": "LDR DE, [ADR]",
"LDAX": "LDR A, [ADR]",
"LHLD": "LDR HL, [ADR]",
"STA": "STR A, [ADR]",
"STAX": "STR A, [ADR]",
"SHLD": "STR HL, [ADR]",
}
mapping_16bit_load_store_move = {
"PUSH": "PUSH",
"POP": "POP",
"LDAX": "LDR A, [ADR]",
"STAX": "STR A, [ADR]",
"LXI": "LDR R2, [ADR], STR R2, [DE]",
}
mapping_8bit_arithmetic_logical = {
"ADD": "ADD",
"ADI": "ADD",
"DAD": "ADD",
"ANA": "AND",
"ANI": "AND",
"INR": "ADD",
"INX": "ADD",
"SUB": "SUB",
"SUI": "SUB",
"DCR": "SUB",
"DCX": "SUB",
"CMP": "CMP",
"CPI": "CMP",
"XRA": "EOR",
"XRI": "EOR",
"ORA": "ORR",
"ORI": "ORR",
"RLC": "ROR",
"RRC": "ROR",
"RAL": "ROR",
"RAR": "ROR",
"CMA": "MVN",
}
mapping_16bit_arithmetic_logical = {
"DAD": "ADD"
}
combined_mapping = {}
combined_mapping.update(mapping_misc_control)
combined_mapping.update(mapping_jumps_calls)
combined_mapping.update(mapping_8bit_load_store_move)
combined_mapping.update(mapping_16bit_load_store_move)
combined_mapping.update(mapping_8bit_arithmetic_logical)
combined_mapping.update(mapping_16bit_arithmetic_logical)
old_mapping = {
"NOP": "NOP", # No operation
"HLT": "NOP", # Halt processor
"STC": "ORRS", # Set carry flag
"RST": "B", # Restart
"SPHL": "MOV", # Stack pointer to HL
"DI": "NOP", # Disable interrupts
"EI": "NOP", # Enable interrupts
"XCHG": "MOV", # Exchange registers
"XTHL": "MOV", # Exchange stack top with HL
"STA": "STR", # Store accumulator direct
"STAX": "STR", # Store accumulator indirect
"LXI": "LDR", # Load immediate register pair
"LDA": "LDR", # Load accumulator direct
"LDAX": "LDR", # Load accumulator indirect
"INR": "ADD", # Increment register
"INX": "ADD", # Increment register pair
"DCR": "SUB", # Decrement register
"DCX": "SUB", # Decrement register pair
"MOV": "MOV", # Move data between registers
# "MOV": "LDR", # Move to/from external device
"MVI": "MOV", # Move immediate data
"RAR": "ROR", # Rotate right
"RAL": "ROR", # Rotate left
"RRC": "ROR", # Rotate right through carry
"RLC": "ROR", # Rotate left through carry
"CMA": "MVN", # Complement accumulator
"CMC": "EOR", # Complement carry flag
"DAD": "ADD", # Add Double
"ADI": "ADD", # Add immediate to accumulator
"ACI": "ADC", # Add immediate to accumulator with carry
"ADD": "ADD", # Add register to accumulator
"ADC": "ADC", # Add register to accumulator with carry
"SUI": "SUB", # Subtract immediate from accumulator
"SUB": "SUB", # Subtract register from accumulator
"SBB": "SBC", # Subtract register from accumulator with borrow
"ANI": "AND", # Logical AND immediate with accumulator
"ANA": "AND", # Logical AND register with accumulator
"ORI": "ORR", # Logical OR immediate with accumulator
"ORA": "ORR", # Logical OR register with accumulator
"XRI": "EOR", # Logical exclusive OR immediate with accumulator
"XRA": "EOR", # Logical exclusive OR register with accumulator
"POP": "POP", # Pop from stack
"PUSH": "PUSH", # Push onto stack
"OUT": "STR", # Output
"CPI": "CMP", # Compare immediate with accumulator
"CMP": "CMP", # Compare register with accumulator
"JMP": "B", # Jump
"JZ": "BEQ", # Jump if zero
"JM": "BMI", # Jump if minus
"JP": "BPL", # Jump if plus
"JPE": "BVS", # Jump if parity even
"JPO": "BVC", # Jump if parity odd
"JNZ": "BNE", # Jump if not zero
"JN": "BVC", # Jump if not parity odd
"JNC": "BCC", # Jump if not carry
"CZ": "BEQ", # Call if zero
"CM": "BMI", # Call if minus
"CP": "CMP", # Call if plus
"CNC": "BCC", # Call if not carry
"CNZ": "BNE", # Call if not zero
"CN": "BVC", # Call if not parity odd
"RET": "BX LR", # Return
"RZ": "BEQ", # Return if zero
"RP": "BPL", # Return if plus
"RPE": "BVS", # Return if parity even
"RPO": "BVS", # Return if parity odd
"RNZ": "BNE", # Return if not zero
"RNC": "BCC", # Return if not carry
"RN": "BVC", # Return if not parity odd
}
MOV_INSTRUCTIONS = {
"""
MOV B,B
MOV B,C
MOV B,D
MOV B,E
MOV B,H
MOV B,L
MOV B,M
MOV B,A
MOV C,B
MOV C,C
MOV C,D
MOV C,E
MOV C,H
MOV C,L
MOV C,M
MOV C,A
MOV D,B
MOV D,C
MOV D,D
MOV D,E
MOV D,H
MOV D,L
MOV D,M
MOV D,A
MOV E,B
MOV E,C
MOV E,D
MOV E,E
MOV E,H
MOV E,L
MOV E,M
MOV E,A
MOV H,B
MOV H,C
MOV H,D
MOV H,E
MOV H,H
MOV H,L
MOV H,M
MOV H,A
MOV L,B
MOV L,C
MOV L,D
MOV L,E
MOV L,H
MOV L,L
MOV L,M
MOV L,A
MOV M,B
MOV M,C
MOV M,D
MOV M,E
MOV M,H
MOV M,L
MOV M,A
MOV A,B
MOV A,C
MOV A,D
MOV A,E
MOV A,H
MOV A,L
MOV A,M
MOV A,A
"""
}