1 #ifndef ASM_H
2 #define ASM_H
3 /* asm.h: token codes and macros for them. protos.
4  * $Id: asm.h,v 1.1.1.1 2003/08/26 16:57:01 varfar Exp $
5  */
6 
7 /* This file is part of `exhaust', a memory array redcode simulator.
8  * Author: M Joonas Pihlaja
9  * Public Domain.
10  */
11 
12 #include "insn.h"
13 
14 #include <stdio.h>
15 /* macros:
16  *	is_tok_opcode()		just what it says
17  *	is_tok_pseudoop()
18  *	is_tok_modifier()
19  *	is_tok_mode()		is a token an addressing mode
20  */
21 
22 /*
23  * asm_line() exit codes:
24  *
25  */
26 
27 #define ASMLINE_PIN  -3		/* PIN encountered */
28 #define ASMLINE_ORG  -2		/* ORG encountered */
29 #define ASMLINE_DONE -1		/* END encountered */
30 #define ASMLINE_NONE  0		/* nothing to assemble, or something ignored */
31 #define ASMLINE_OK    1		/* assembled instruction OK */
32 
33 /*
34  * Token codes for the lexer.
35  */
36 enum {
37   TOK_FIRST = 256,		/* not used */
38 
39   TOK_OPCODE_START,		/* opcodes */
40   TOK_DAT,			/* same order as insn.h opcodes. */
41   TOK_SPL,
42   TOK_MOV,
43   TOK_DJN,
44   TOK_ADD,
45   TOK_JMZ,
46   TOK_SUB,
47   TOK_SEQ,
48   TOK_SNE,
49   TOK_SLT,
50   TOK_JMN,
51   TOK_JMP,
52   TOK_NOP,
53   TOK_MUL,
54   TOK_MOD,
55   TOK_DIV,
56   TOK_LDP,
57   TOK_STP,			/* 18 */
58   TOK_OPCODE_STOP,
59 
60   TOK_PSEUDOOP_START,
61     TOK_ORG,			/* pseudo-ops and start label */
62     TOK_END,
63     TOK_PIN,
64   TOK_PSEUDOOP_STOP,
65 
66   TOK_MODIFIER_START,
67     TOK_mF, TOK_mA, TOK_mB,	/* modifiers */
68     TOK_mAB, TOK_mBA, TOK_mX, TOK_mI,
69   TOK_MODIFIER_STOP,
70 
71   TOK_MODE_START,
72     TOK_DIRECT, TOK_IMMEDIATE,	/* addressing modes */
73     TOK_BINDIRECT,  TOK_BPREDEC,
74     TOK_BPOSTINC,  TOK_AINDIRECT,
75     TOK_APREDEC,  TOK_APOSTINC,	/* 8 */
76   TOK_MODE_STOP,
77 
78   TOK_START,
79   TOK_STR, TOK_INT,		/* string token, int token  */
80 
81   TOK_LAST			/* sentinel */
82 };
83 
84 
85 #define TOK_ERR TOK_FIRST	/* unused */
86 
87 /*
88  * Macros to identify a token type from a token code.
89  */
90 #define is_tok_opcode(t)   ( t > TOK_OPCODE_START && t < TOK_OPCODE_STOP )
91 #define is_tok_pseudoop(t) ( t > TOK_PSEUDOOP_START && t < TOK_PSEUDOOP_STOP )
92 #define is_tok_modifier(t) ( t > TOK_MODIFIER_START && t < TOK_MODIFIER_STOP )
93 #define is_tok_mode(t)     ( t > TOK_MODE_START && t < TOK_MODE_STOP )
94 
95 
96 /*
97  * protos
98  */
99 int asm_line( const char *line, insn_t *in, unsigned int CORESIZE );
100 void asm_file( FILE *F, warrior_t *w, unsigned int CORESIZE );
101 void asm_fname( const char *fname, warrior_t *w, unsigned int CORESIZE );
102 void dis1( char *s, insn_t in, unsigned int CORESIZE );
103 void discore( const insn_t *core, int start, int end, unsigned int CORESIZE );
104 
105 extern const char
106 	*MNEMONIC_OPCODE[OPCODE_LAST],
107 	*MNEMONIC_MODIFIER[MODIFIER_LAST],
108 	MNEMONIC_ADDRMODE[ADDRMODE_LAST];
109 
110 #endif /* ASM_H */
111