My Project
lc3.h
Go to the documentation of this file.
1 #ifndef __LC3_H__
2 #define __LC3_H__
3 
4 /*
5  * "Copyright (c) 2014 by Fritz Sieker."
6  * based on ideas/code by Steven S. Lumetta
7  *
8  * Permission to use, copy, modify, and distribute this software and its
9  * documentation for any purpose, without fee, and without written
10  * agreement is hereby granted, provided that the above copyright notice
11  * and the following two paragraphs appear in all copies of this software.
12  *
13  * IN NO EVENT SHALL THE AUTHOR BE LIABLE TO ANY PARTY FOR DIRECT,
14  * INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES ARISING OUT
15  * OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF THE AUTHOR
16  * HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
17  *
18  * THE AUTHOR SPECIFICALLY DISCLAIMS ANY WARRANTIES, INCLUDING, BUT NOT
19  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
20  * A PARTICULAR PURPOSE. THE SOFTWARE PROVIDED HEREUNDER IS ON AN "AS IS"
21  * BASIS, AND THE AUTHOR NO OBLIGATION TO PROVIDE MAINTENANCE, SUPPORT,
22  * UPDATES, ENHANCEMENTS, OR MODIFICATIONS."
23  */
24 
34 #include <stdio.h>
35 
37 #ifndef LC3_VAR
38 #define LC3_VAR extern
39 #endif
40 
41 #include "symbol.h"
42 
47 char* strdup(const char *);
48 
50 #define LC3_WORD unsigned short
51 
53 #define LC3_MEM_SIZE 65536
54 
56 #define LC3_NUM_REGS 8
57 
59 #define RETURN_ADDR_REG 7
60 
63 
66 
71 typedef enum opcode {
72  OP_INVALID = -1,
106 } opcode_t;
107 
115 typedef enum operand {
116  FMT_R1 = 0x001,
117  FMT_R2 = 0x002,
118  FMT_R3 = 0x004,
119  FMT_CC = 0x008,
120  FMT_IMM5 = 0x010,
121  FMT_IMM6 = 0x020,
122  FMT_VEC8 = 0x040,
123  FMT_ASC8 = 0x080,
124  FMT_PCO9 = 0x100,
125  FMT_PCO11 = 0x200,
126  FMT_IMM16 = 0x400,
127  FMT_STR = 0x800
128 } operand_t;
129 
142 typedef enum operands {
143  FMT_ = 0,
144  FMT_RRR = (FMT_R1 | FMT_R2 | FMT_R3),
145  FMT_RRI5 = (FMT_R1 | FMT_R2 | FMT_IMM5),
146  FMT_L = FMT_PCO9,
147  FMT_R = FMT_R2,
148  FMT_I11 = FMT_PCO11,
149  FMT_RL = (FMT_R1 | FMT_PCO9),
150  FMT_RRI6 = (FMT_R1 | FMT_R2 | FMT_IMM6),
151  FMT_RR = (FMT_R1 | FMT_R2),
152  FMT_V = FMT_VEC8,
153  FMT_A = FMT_ASC8,
154  FMT_16 = FMT_IMM16,
155  FMT_S = FMT_STR
156 } operands_t;
157 
161 typedef struct inst_format {
162  char* name;
164  int prototype;
165 } inst_format_t;
166 
172 typedef struct LC3_inst {
173  int formBit;
176 } LC3_inst_t;
177 
182 char lc3_escaped_char (char c);
183 
191 
196 const char* lc3_get_format_name (operands_t format);
197 
202 const char* lc3_get_opcode_name (opcode_t op);
203 
209 
214 int lc3_read_LC3_word (FILE *f);
215 
221 void lc3_read_sym_table (FILE* sym_file);
222 
227 void lc3_write_LC3_word (FILE* f, int value);
228 
232 void lc3_write_sym_table (FILE* sym_file);
233 
242 int lc3_get_int (char* token, int* value);
243 
251 int lc3_get_address (char* token, int* value);
252 
253 #endif /* __LC3_H__ */
254 
Definition: lc3.h:122
Definition: lc3.h:83
Definition: lc3.h:91
Definition: lc3.h:72
int formBit
Definition: lc3.h:173
Definition: lc3.h:124
LC3_VAR int inHex
Definition: lc3.h:62
Definition: lc3.h:95
#define LC3_VAR
Definition: lc3.h:38
Definition: lc3.h:98
Defines the interface to symbol.c functions (do not modify)
void lc3_read_sym_table(FILE *sym_file)
Definition: lc3.h:101
Definition: lc3.h:161
Definition: lc3.h:104
void lc3_write_sym_table(FILE *sym_file)
Definition: lc3.h:121
Definition: lc3.h:123
Definition: lc3.h:77
Definition: lc3.h:81
Definition: lc3.h:75
enum operand operand_t
Definition: lc3.h:105
Definition: lc3.h:127
Definition: lc3.h:99
struct inst_format inst_format_t
Definition: lc3.h:79
LC3_inst_t * lc3_get_inst_info(opcode_t opcode)
opcode
Definition: lc3.h:71
Definition: lc3.h:120
Definition: lc3.h:125
Definition: lc3.h:119
operand
Definition: lc3.h:115
Definition: lc3.h:172
Definition: lc3.h:103
int lc3_get_address(char *token, int *value)
Definition: lc3.h:117
enum opcode opcode_t
struct LC3_inst LC3_inst_t
Definition: lc3.h:74
const char * lc3_get_format_name(operands_t format)
LC3_VAR sym_table_t * lc3_sym_tab
Definition: lc3.h:65
Definition: lc3.h:84
struct sym_table sym_table_t
Definition: symbol.h:43
Definition: lc3.h:100
const char * lc3_get_operand_name(operand_t operand)
char * strdup(const char *)
int lc3_get_int(char *token, int *value)
Definition: lc3.h:92
Definition: lc3.h:88
const char * lc3_get_opcode_name(opcode_t op)
inst_format_t forms[2]
Definition: lc3.h:175
operands_t operands
Definition: lc3.h:163
char * name
Definition: lc3.h:162
Definition: lc3.h:102
Definition: lc3.h:80
char lc3_escaped_char(char c)
Definition: lc3.h:76
Definition: lc3.h:73
void lc3_write_LC3_word(FILE *f, int value)
enum operands operands_t
Definition: lc3.h:87
Definition: lc3.h:126
Definition: lc3.h:93
int prototype
Definition: lc3.h:164
Definition: lc3.h:78
Definition: lc3.h:90
Definition: lc3.h:89
Definition: lc3.h:97
Definition: lc3.h:116
int lc3_read_LC3_word(FILE *f)
Definition: lc3.h:85
operands
Definition: lc3.h:142
Definition: lc3.h:96
Definition: lc3.h:118
Definition: lc3.h:86
Definition: lc3.h:82