intel_8080_kit/asm/
mod.rs

1//! `src/asm/mod.rs` is automatically generated by `./utils/gen.py` from `utils/opcodes.txt`.
2//! don't modify this file directly, instead run `python3 ./utils/gen.py`.
3
4use super::op::*;
5pub mod lexer;
6
7pub fn codegen(ops: &[Opcode]) -> Vec<u8> {
8    let mut bin = Vec::new();
9
10    let mut i = 0;
11    while i < ops.len() {
12        match ops[i] {
13            Opcode::Nop => {
14                bin.push(0x00u8);
15            }
16            Opcode::LxiB(b2, b1) => {
17                bin.push(0x01u8);
18                bin.push(b1);
19                bin.push(b2);
20            }
21            Opcode::StaxB => {
22                bin.push(0x02u8);
23            }
24            Opcode::InxB => {
25                bin.push(0x03u8);
26            }
27            Opcode::InrB => {
28                bin.push(0x04u8);
29            }
30            Opcode::DcrB => {
31                bin.push(0x05u8);
32            }
33            Opcode::MviB(b1) => {
34                bin.push(0x06u8);
35                bin.push(b1);
36            }
37            Opcode::Rlc => {
38                bin.push(0x07u8);
39            }
40            Opcode::DadB => {
41                bin.push(0x09u8);
42            }
43            Opcode::LdaxB => {
44                bin.push(0x0au8);
45            }
46            Opcode::DcxB => {
47                bin.push(0x0bu8);
48            }
49            Opcode::InrC => {
50                bin.push(0x0cu8);
51            }
52            Opcode::DcrC => {
53                bin.push(0x0du8);
54            }
55            Opcode::MviC(b1) => {
56                bin.push(0x0eu8);
57                bin.push(b1);
58            }
59            Opcode::Rrc => {
60                bin.push(0x0fu8);
61            }
62            Opcode::LxiD(b2, b1) => {
63                bin.push(0x11u8);
64                bin.push(b1);
65                bin.push(b2);
66            }
67            Opcode::StaxD => {
68                bin.push(0x12u8);
69            }
70            Opcode::InxD => {
71                bin.push(0x13u8);
72            }
73            Opcode::InrD => {
74                bin.push(0x14u8);
75            }
76            Opcode::DcrD => {
77                bin.push(0x15u8);
78            }
79            Opcode::MviD(b1) => {
80                bin.push(0x16u8);
81                bin.push(b1);
82            }
83            Opcode::Ral => {
84                bin.push(0x17u8);
85            }
86            Opcode::DadD => {
87                bin.push(0x19u8);
88            }
89            Opcode::LdaxD => {
90                bin.push(0x1au8);
91            }
92            Opcode::DcxD => {
93                bin.push(0x1bu8);
94            }
95            Opcode::InrE => {
96                bin.push(0x1cu8);
97            }
98            Opcode::DcrE => {
99                bin.push(0x1du8);
100            }
101            Opcode::MviE(b1) => {
102                bin.push(0x1eu8);
103                bin.push(b1);
104            }
105            Opcode::Rar => {
106                bin.push(0x1fu8);
107            }
108            Opcode::LxiH(b2, b1) => {
109                bin.push(0x21u8);
110                bin.push(b1);
111                bin.push(b2);
112            }
113            Opcode::Shld(s1) => {
114                bin.push(0x22u8);
115                let b = s1.to_le_bytes();
116                bin.push(b[0]);
117                bin.push(b[1]);
118            }
119            Opcode::InxH => {
120                bin.push(0x23u8);
121            }
122            Opcode::InrH => {
123                bin.push(0x24u8);
124            }
125            Opcode::DcrH => {
126                bin.push(0x25u8);
127            }
128            Opcode::MviH(b1) => {
129                bin.push(0x26u8);
130                bin.push(b1);
131            }
132            Opcode::Daa => {
133                bin.push(0x27u8);
134            }
135            Opcode::DadH => {
136                bin.push(0x29u8);
137            }
138            Opcode::Lhld(s1) => {
139                bin.push(0x2au8);
140                let b = s1.to_le_bytes();
141                bin.push(b[0]);
142                bin.push(b[1]);
143            }
144            Opcode::DcxH => {
145                bin.push(0x2bu8);
146            }
147            Opcode::InrL => {
148                bin.push(0x2cu8);
149            }
150            Opcode::DcrL => {
151                bin.push(0x2du8);
152            }
153            Opcode::MviL(b1) => {
154                bin.push(0x2eu8);
155                bin.push(b1);
156            }
157            Opcode::Cma => {
158                bin.push(0x2fu8);
159            }
160            Opcode::LxiSp(b2, b1) => {
161                bin.push(0x31u8);
162                bin.push(b1);
163                bin.push(b2);
164            }
165            Opcode::Sta(s1) => {
166                bin.push(0x32u8);
167                let b = s1.to_le_bytes();
168                bin.push(b[0]);
169                bin.push(b[1]);
170            }
171            Opcode::InxSp => {
172                bin.push(0x33u8);
173            }
174            Opcode::InrM => {
175                bin.push(0x34u8);
176            }
177            Opcode::DcrM => {
178                bin.push(0x35u8);
179            }
180            Opcode::MviM(b1) => {
181                bin.push(0x36u8);
182                bin.push(b1);
183            }
184            Opcode::Stc => {
185                bin.push(0x37u8);
186            }
187            Opcode::DadSp => {
188                bin.push(0x39u8);
189            }
190            Opcode::Lda(s1) => {
191                bin.push(0x3au8);
192                let b = s1.to_le_bytes();
193                bin.push(b[0]);
194                bin.push(b[1]);
195            }
196            Opcode::DcxSp => {
197                bin.push(0x3bu8);
198            }
199            Opcode::InrA => {
200                bin.push(0x3cu8);
201            }
202            Opcode::DcrA => {
203                bin.push(0x3du8);
204            }
205            Opcode::MviA(b1) => {
206                bin.push(0x3eu8);
207                bin.push(b1);
208            }
209            Opcode::Cmc => {
210                bin.push(0x3fu8);
211            }
212            Opcode::MovBB => {
213                bin.push(0x40u8);
214            }
215            Opcode::MovBC => {
216                bin.push(0x41u8);
217            }
218            Opcode::MovBD => {
219                bin.push(0x42u8);
220            }
221            Opcode::MovBE => {
222                bin.push(0x43u8);
223            }
224            Opcode::MovBH => {
225                bin.push(0x44u8);
226            }
227            Opcode::MovBL => {
228                bin.push(0x45u8);
229            }
230            Opcode::MovBM => {
231                bin.push(0x46u8);
232            }
233            Opcode::MovBA => {
234                bin.push(0x47u8);
235            }
236            Opcode::MovCB => {
237                bin.push(0x48u8);
238            }
239            Opcode::MovCC => {
240                bin.push(0x49u8);
241            }
242            Opcode::MovCD => {
243                bin.push(0x4au8);
244            }
245            Opcode::MovCE => {
246                bin.push(0x4bu8);
247            }
248            Opcode::MovCH => {
249                bin.push(0x4cu8);
250            }
251            Opcode::MovCL => {
252                bin.push(0x4du8);
253            }
254            Opcode::MovCM => {
255                bin.push(0x4eu8);
256            }
257            Opcode::MovCA => {
258                bin.push(0x4fu8);
259            }
260            Opcode::MovDB => {
261                bin.push(0x50u8);
262            }
263            Opcode::MovDC => {
264                bin.push(0x51u8);
265            }
266            Opcode::MovDD => {
267                bin.push(0x52u8);
268            }
269            Opcode::MovDE => {
270                bin.push(0x53u8);
271            }
272            Opcode::MovDH => {
273                bin.push(0x54u8);
274            }
275            Opcode::MovDL => {
276                bin.push(0x55u8);
277            }
278            Opcode::MovDM => {
279                bin.push(0x56u8);
280            }
281            Opcode::MovDA => {
282                bin.push(0x57u8);
283            }
284            Opcode::MovEB => {
285                bin.push(0x58u8);
286            }
287            Opcode::MovEC => {
288                bin.push(0x59u8);
289            }
290            Opcode::MovED => {
291                bin.push(0x5au8);
292            }
293            Opcode::MovEE => {
294                bin.push(0x5bu8);
295            }
296            Opcode::MovEH => {
297                bin.push(0x5cu8);
298            }
299            Opcode::MovEL => {
300                bin.push(0x5du8);
301            }
302            Opcode::MovEM => {
303                bin.push(0x5eu8);
304            }
305            Opcode::MovEA => {
306                bin.push(0x5fu8);
307            }
308            Opcode::MovHB => {
309                bin.push(0x60u8);
310            }
311            Opcode::MovHC => {
312                bin.push(0x61u8);
313            }
314            Opcode::MovHD => {
315                bin.push(0x62u8);
316            }
317            Opcode::MovHE => {
318                bin.push(0x63u8);
319            }
320            Opcode::MovHH => {
321                bin.push(0x64u8);
322            }
323            Opcode::MovHL => {
324                bin.push(0x65u8);
325            }
326            Opcode::MovHM => {
327                bin.push(0x66u8);
328            }
329            Opcode::MovHA => {
330                bin.push(0x67u8);
331            }
332            Opcode::MovLB => {
333                bin.push(0x68u8);
334            }
335            Opcode::MovLC => {
336                bin.push(0x69u8);
337            }
338            Opcode::MovLD => {
339                bin.push(0x6au8);
340            }
341            Opcode::MovLE => {
342                bin.push(0x6bu8);
343            }
344            Opcode::MovLH => {
345                bin.push(0x6cu8);
346            }
347            Opcode::MovLL => {
348                bin.push(0x6du8);
349            }
350            Opcode::MovLM => {
351                bin.push(0x6eu8);
352            }
353            Opcode::MovLA => {
354                bin.push(0x6fu8);
355            }
356            Opcode::MovMB => {
357                bin.push(0x70u8);
358            }
359            Opcode::MovMC => {
360                bin.push(0x71u8);
361            }
362            Opcode::MovMD => {
363                bin.push(0x72u8);
364            }
365            Opcode::MovME => {
366                bin.push(0x73u8);
367            }
368            Opcode::MovMH => {
369                bin.push(0x74u8);
370            }
371            Opcode::MovML => {
372                bin.push(0x75u8);
373            }
374            Opcode::Hlt => {
375                bin.push(0x76u8);
376            }
377            Opcode::MovMA => {
378                bin.push(0x77u8);
379            }
380            Opcode::MovAB => {
381                bin.push(0x78u8);
382            }
383            Opcode::MovAC => {
384                bin.push(0x79u8);
385            }
386            Opcode::MovAD => {
387                bin.push(0x7au8);
388            }
389            Opcode::MovAE => {
390                bin.push(0x7bu8);
391            }
392            Opcode::MovAH => {
393                bin.push(0x7cu8);
394            }
395            Opcode::MovAL => {
396                bin.push(0x7du8);
397            }
398            Opcode::MovAM => {
399                bin.push(0x7eu8);
400            }
401            Opcode::MovAA => {
402                bin.push(0x7fu8);
403            }
404            Opcode::AddB => {
405                bin.push(0x80u8);
406            }
407            Opcode::AddC => {
408                bin.push(0x81u8);
409            }
410            Opcode::AddD => {
411                bin.push(0x82u8);
412            }
413            Opcode::AddE => {
414                bin.push(0x83u8);
415            }
416            Opcode::AddH => {
417                bin.push(0x84u8);
418            }
419            Opcode::AddL => {
420                bin.push(0x85u8);
421            }
422            Opcode::AddM => {
423                bin.push(0x86u8);
424            }
425            Opcode::AddA => {
426                bin.push(0x87u8);
427            }
428            Opcode::AdcB => {
429                bin.push(0x88u8);
430            }
431            Opcode::AdcC => {
432                bin.push(0x89u8);
433            }
434            Opcode::AdcD => {
435                bin.push(0x8au8);
436            }
437            Opcode::AdcE => {
438                bin.push(0x8bu8);
439            }
440            Opcode::AdcH => {
441                bin.push(0x8cu8);
442            }
443            Opcode::AdcL => {
444                bin.push(0x8du8);
445            }
446            Opcode::AdcM => {
447                bin.push(0x8eu8);
448            }
449            Opcode::AdcA => {
450                bin.push(0x8fu8);
451            }
452            Opcode::SubB => {
453                bin.push(0x90u8);
454            }
455            Opcode::SubC => {
456                bin.push(0x91u8);
457            }
458            Opcode::SubD => {
459                bin.push(0x92u8);
460            }
461            Opcode::SubE => {
462                bin.push(0x93u8);
463            }
464            Opcode::SubH => {
465                bin.push(0x94u8);
466            }
467            Opcode::SubL => {
468                bin.push(0x95u8);
469            }
470            Opcode::SubM => {
471                bin.push(0x96u8);
472            }
473            Opcode::SubA => {
474                bin.push(0x97u8);
475            }
476            Opcode::SbbB => {
477                bin.push(0x98u8);
478            }
479            Opcode::SbbC => {
480                bin.push(0x99u8);
481            }
482            Opcode::SbbD => {
483                bin.push(0x9au8);
484            }
485            Opcode::SbbE => {
486                bin.push(0x9bu8);
487            }
488            Opcode::SbbH => {
489                bin.push(0x9cu8);
490            }
491            Opcode::SbbL => {
492                bin.push(0x9du8);
493            }
494            Opcode::SbbM => {
495                bin.push(0x9eu8);
496            }
497            Opcode::SbbA => {
498                bin.push(0x9fu8);
499            }
500            Opcode::AnaB => {
501                bin.push(0xa0u8);
502            }
503            Opcode::AnaC => {
504                bin.push(0xa1u8);
505            }
506            Opcode::AnaD => {
507                bin.push(0xa2u8);
508            }
509            Opcode::AnaE => {
510                bin.push(0xa3u8);
511            }
512            Opcode::AnaH => {
513                bin.push(0xa4u8);
514            }
515            Opcode::AnaL => {
516                bin.push(0xa5u8);
517            }
518            Opcode::AnaM => {
519                bin.push(0xa6u8);
520            }
521            Opcode::AnaA => {
522                bin.push(0xa7u8);
523            }
524            Opcode::XraB => {
525                bin.push(0xa8u8);
526            }
527            Opcode::XraC => {
528                bin.push(0xa9u8);
529            }
530            Opcode::XraD => {
531                bin.push(0xaau8);
532            }
533            Opcode::XraE => {
534                bin.push(0xabu8);
535            }
536            Opcode::XraH => {
537                bin.push(0xacu8);
538            }
539            Opcode::XraL => {
540                bin.push(0xadu8);
541            }
542            Opcode::XraM => {
543                bin.push(0xaeu8);
544            }
545            Opcode::XraA => {
546                bin.push(0xafu8);
547            }
548            Opcode::OraB => {
549                bin.push(0xb0u8);
550            }
551            Opcode::OraC => {
552                bin.push(0xb1u8);
553            }
554            Opcode::OraD => {
555                bin.push(0xb2u8);
556            }
557            Opcode::OraE => {
558                bin.push(0xb3u8);
559            }
560            Opcode::OraH => {
561                bin.push(0xb4u8);
562            }
563            Opcode::OraL => {
564                bin.push(0xb5u8);
565            }
566            Opcode::OraM => {
567                bin.push(0xb6u8);
568            }
569            Opcode::OraA => {
570                bin.push(0xb7u8);
571            }
572            Opcode::CmpB => {
573                bin.push(0xb8u8);
574            }
575            Opcode::CmpC => {
576                bin.push(0xb9u8);
577            }
578            Opcode::CmpD => {
579                bin.push(0xbau8);
580            }
581            Opcode::CmpE => {
582                bin.push(0xbbu8);
583            }
584            Opcode::CmpH => {
585                bin.push(0xbcu8);
586            }
587            Opcode::CmpL => {
588                bin.push(0xbdu8);
589            }
590            Opcode::CmpM => {
591                bin.push(0xbeu8);
592            }
593            Opcode::CmpA => {
594                bin.push(0xbfu8);
595            }
596            Opcode::Rnz => {
597                bin.push(0xc0u8);
598            }
599            Opcode::PopB => {
600                bin.push(0xc1u8);
601            }
602            Opcode::Jnz(s1) => {
603                bin.push(0xc2u8);
604                let b = s1.to_le_bytes();
605                bin.push(b[0]);
606                bin.push(b[1]);
607            }
608            Opcode::Jmp(s1) => {
609                bin.push(0xc3u8);
610                let b = s1.to_le_bytes();
611                bin.push(b[0]);
612                bin.push(b[1]);
613            }
614            Opcode::Cnz(s1) => {
615                bin.push(0xc4u8);
616                let b = s1.to_le_bytes();
617                bin.push(b[0]);
618                bin.push(b[1]);
619            }
620            Opcode::PushB => {
621                bin.push(0xc5u8);
622            }
623            Opcode::Adi(b1) => {
624                bin.push(0xc6u8);
625                bin.push(b1);
626            }
627            Opcode::Rst0 => {
628                bin.push(0xc7u8);
629            }
630            Opcode::Rz => {
631                bin.push(0xc8u8);
632            }
633            Opcode::Ret => {
634                bin.push(0xc9u8);
635            }
636            Opcode::Jz(s1) => {
637                bin.push(0xcau8);
638                let b = s1.to_le_bytes();
639                bin.push(b[0]);
640                bin.push(b[1]);
641            }
642            Opcode::Cz(s1) => {
643                bin.push(0xccu8);
644                let b = s1.to_le_bytes();
645                bin.push(b[0]);
646                bin.push(b[1]);
647            }
648            Opcode::Call(s1) => {
649                bin.push(0xcdu8);
650                let b = s1.to_le_bytes();
651                bin.push(b[0]);
652                bin.push(b[1]);
653            }
654            Opcode::Aci(b1) => {
655                bin.push(0xceu8);
656                bin.push(b1);
657            }
658            Opcode::Rst1 => {
659                bin.push(0xcfu8);
660            }
661            Opcode::Rnc => {
662                bin.push(0xd0u8);
663            }
664            Opcode::PopD => {
665                bin.push(0xd1u8);
666            }
667            Opcode::Jnc(s1) => {
668                bin.push(0xd2u8);
669                let b = s1.to_le_bytes();
670                bin.push(b[0]);
671                bin.push(b[1]);
672            }
673            Opcode::Out(b1) => {
674                bin.push(0xd3u8);
675                bin.push(b1);
676            }
677            Opcode::Cnc(s1) => {
678                bin.push(0xd4u8);
679                let b = s1.to_le_bytes();
680                bin.push(b[0]);
681                bin.push(b[1]);
682            }
683            Opcode::PushD => {
684                bin.push(0xd5u8);
685            }
686            Opcode::Sui(b1) => {
687                bin.push(0xd6u8);
688                bin.push(b1);
689            }
690            Opcode::Rst2 => {
691                bin.push(0xd7u8);
692            }
693            Opcode::Rc => {
694                bin.push(0xd8u8);
695            }
696            Opcode::Jc(s1) => {
697                bin.push(0xdau8);
698                let b = s1.to_le_bytes();
699                bin.push(b[0]);
700                bin.push(b[1]);
701            }
702            Opcode::In(b1) => {
703                bin.push(0xdbu8);
704                bin.push(b1);
705            }
706            Opcode::Cc(s1) => {
707                bin.push(0xdcu8);
708                let b = s1.to_le_bytes();
709                bin.push(b[0]);
710                bin.push(b[1]);
711            }
712            Opcode::Sbi(b1) => {
713                bin.push(0xdeu8);
714                bin.push(b1);
715            }
716            Opcode::Rst3 => {
717                bin.push(0xdfu8);
718            }
719            Opcode::Rpo => {
720                bin.push(0xe0u8);
721            }
722            Opcode::PopH => {
723                bin.push(0xe1u8);
724            }
725            Opcode::Jpo(s1) => {
726                bin.push(0xe2u8);
727                let b = s1.to_le_bytes();
728                bin.push(b[0]);
729                bin.push(b[1]);
730            }
731            Opcode::Xthl => {
732                bin.push(0xe3u8);
733            }
734            Opcode::Cpo(s1) => {
735                bin.push(0xe4u8);
736                let b = s1.to_le_bytes();
737                bin.push(b[0]);
738                bin.push(b[1]);
739            }
740            Opcode::PushH => {
741                bin.push(0xe5u8);
742            }
743            Opcode::Ani(b1) => {
744                bin.push(0xe6u8);
745                bin.push(b1);
746            }
747            Opcode::Rst4 => {
748                bin.push(0xe7u8);
749            }
750            Opcode::Rpe => {
751                bin.push(0xe8u8);
752            }
753            Opcode::Pchl => {
754                bin.push(0xe9u8);
755            }
756            Opcode::Jpe(s1) => {
757                bin.push(0xeau8);
758                let b = s1.to_le_bytes();
759                bin.push(b[0]);
760                bin.push(b[1]);
761            }
762            Opcode::Xchg => {
763                bin.push(0xebu8);
764            }
765            Opcode::Cpe(s1) => {
766                bin.push(0xecu8);
767                let b = s1.to_le_bytes();
768                bin.push(b[0]);
769                bin.push(b[1]);
770            }
771            Opcode::Xri(b1) => {
772                bin.push(0xeeu8);
773                bin.push(b1);
774            }
775            Opcode::Rst5 => {
776                bin.push(0xefu8);
777            }
778            Opcode::Rp => {
779                bin.push(0xf0u8);
780            }
781            Opcode::PopPsw => {
782                bin.push(0xf1u8);
783            }
784            Opcode::Jp(s1) => {
785                bin.push(0xf2u8);
786                let b = s1.to_le_bytes();
787                bin.push(b[0]);
788                bin.push(b[1]);
789            }
790            Opcode::Di => {
791                bin.push(0xf3u8);
792            }
793            Opcode::Cp(s1) => {
794                bin.push(0xf4u8);
795                let b = s1.to_le_bytes();
796                bin.push(b[0]);
797                bin.push(b[1]);
798            }
799            Opcode::PushPsw => {
800                bin.push(0xf5u8);
801            }
802            Opcode::Ori(b1) => {
803                bin.push(0xf6u8);
804                bin.push(b1);
805            }
806            Opcode::Rst6 => {
807                bin.push(0xf7u8);
808            }
809            Opcode::Rm => {
810                bin.push(0xf8u8);
811            }
812            Opcode::Sphl => {
813                bin.push(0xf9u8);
814            }
815            Opcode::Jm(s1) => {
816                bin.push(0xfau8);
817                let b = s1.to_le_bytes();
818                bin.push(b[0]);
819                bin.push(b[1]);
820            }
821            Opcode::Ei => {
822                bin.push(0xfbu8);
823            }
824            Opcode::Cm(s1) => {
825                bin.push(0xfcu8);
826                let b = s1.to_le_bytes();
827                bin.push(b[0]);
828                bin.push(b[1]);
829            }
830            Opcode::Cpi(b1) => {
831                bin.push(0xfeu8);
832                bin.push(b1);
833            }
834            Opcode::Rst7 => {
835                bin.push(0xffu8);
836            }
837        }
838        i += 1;
839    }
840
841    bin
842}