lc3.h
Go to the documentation of this file.
1 #ifndef __LC3_H__
2 #define __LC3_H__
3 
4 /*
5  * "Copyright (c) 2012 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  * that the files COPYING and NO_WARRANTY are included verbatim with
13  * any distribution, and that the contents of the file README are included
14  * verbatim as part of a file named README with any distribution.
15  *
16  * IN NO EVENT SHALL THE AUTHOR BE LIABLE TO ANY PARTY FOR DIRECT,
17  * INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES ARISING OUT
18  * OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF THE AUTHOR
19  * HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
20  *
21  * THE AUTHOR SPECIFICALLY DISCLAIMS ANY WARRANTIES, INCLUDING, BUT NOT
22  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
23  * A PARTICULAR PURPOSE. THE SOFTWARE PROVIDED HEREUNDER IS ON AN "AS IS"
24  * BASIS, AND THE AUTHOR NO OBLIGATION TO PROVIDE MAINTENANCE, SUPPORT,
25  * UPDATES, ENHANCEMENTS, OR MODIFICATIONS."
26  */
27 
38 #define LC3_WORD unsigned short
39 
41 #define LC3_MEM_SIZE 65538
42 
44 #define LC3_NUM_REGS 8
45 
47 #define RETURN_ADDR_REG 7
48 
50 typedef enum opcode_t {
51  OP_BR = 0,
52  OP_ADD,
53  OP_LD,
54  OP_ST,
55  OP_JSR,
56  OP_AND,
57  OP_LDR,
58  OP_STR,
59  OP_RTI,
60  OP_NOT,
61  OP_LDI,
62  OP_STI,
63  OP_JMP_RET,
64 
65 #if defined SHIFT_OP
66  OP_SHIFT,
67 #elif defined STACK_OP
68  OP_PUSHPOP,
69 #elif defined FLADD_OP
70  OP_FLADD,
71 #else
72  OP_RESERVED,
73 #endif
74 
75  OP_LEA,
76  OP_TRAP,
77  NUM_OPS
78 } opcode_t;
79 
87 typedef enum inst_field {
88  FMT_R1 = 0x001,
89  FMT_R2 = 0x002,
90  FMT_R3 = 0x004,
91  FMT_CC = 0x008,
92  FMT_IMM5 = 0x010,
93  FMT_IMM6 = 0x020,
94  FMT_VEC8 = 0x040,
95  FMT_ASC8 = 0x080,
96  FMT_IMM9 = 0x100,
97  FMT_IMM11 = 0x200,
98  FMT_IMM16 = 0x400
99 } inst_field_t;
100 
107 typedef enum inst_format {
108  FMT_ = 0,
109  FMT_RRR = (FMT_R1 | FMT_R2 | FMT_R3),
110  FMT_RRI5 = (FMT_R1 | FMT_R2 | FMT_IMM5),
111  FMT_CL = (FMT_CC | FMT_IMM9),
112  FMT_R = FMT_R2,
113  FMT_I11 = FMT_IMM11,
114  FMT_RL = (FMT_R1 | FMT_IMM9),
115  FMT_RRI6 = (FMT_R1 | FMT_R2 | FMT_IMM6),
116  FMT_RR = (FMT_R1 | FMT_R2),
117  FMT_V = FMT_VEC8,
118  FMT_A = FMT_ASC8,
119  FMT_16 = FMT_IMM16
120 } inst_format_t;
121 
126 typedef struct inst_info {
127  char* name[2];
129  int opBit;
133 } inst_info_t;
134 
140 
141 #endif /* __LC3_H__ */
142