assembler.h
Go to the documentation of this file.
1 #ifndef __ASSEMBLER_H__
2 #define __ASSEMBLER_H__
3 
4 /*
5  * "Copyright (c) 2015-16 by Fritz Sieker."
6  *
7  * Permission to use, copy, modify, and distribute this software and its
8  * documentation for any purpose, without fee, and without written
9  * agreement is hereby granted, provided that the above copyright notice
10  * and the following two paragraphs appear in all copies of this software.
11  *
12  * IN NO EVENT SHALL THE AUTHOR BE LIABLE TO ANY PARTY FOR DIRECT,
13  * INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES ARISING OUT
14  * OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF THE AUTHOR
15  * HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
16  *
17  * THE AUTHOR SPECIFICALLY DISCLAIMS ANY WARRANTIES, INCLUDING, BUT NOT
18  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
19  * A PARTICULAR PURPOSE. THE SOFTWARE PROVIDED HEREUNDER IS ON AN "AS IS"
20  * BASIS, AND THE AUTHOR NO OBLIGATION TO PROVIDE MAINTENANCE, SUPPORT,
21  * UPDATES, ENHANCEMENTS, OR MODIFICATIONS."
22  */
23 
52 #include <stdbool.h>
53 
54 #include "lc3.h"
55 #include "symbol.h"
56 
58 #ifndef LC3AS_VAR
59 #define LC3AS_VAR extern
60 #endif
61 
63 #define ERR_OPEN_READ "could not open '%s' for reading."
64 #define ERR_OPEN_WRITE "could not open '%s' for writing."
65 #define ERR_LINE_TOO_LONG "source line too long (max is %d)"
66 #define ERR_NO_ORIG "no .ORIG directive found"
67 #define ERR_MULTIPLE_ORIG "multiple .ORIG found"
68 #define ERR_NO_END "no .END directive found"
69 #define ERR_ORIG_NOT_1ST "instruction(s) appear before .ORIG"
70 #define ERR_END_NOT_LAST "instruction(s) appear after .END - ignored"
71 #define ERR_EXPECTED_COMMA "expected comma, got '%s'"
72 #define ERR_EXPECTED_REG "expected register (R0-R7), got '%s'"
73 #define ERR_EXPECT_REG_IMM "expected register or immediate, got '%s'"
74 #define ERR_BAD_LABEL "label '%s' contains illegal characters"
75 #define ERR_MISSING_OP "expected LC3 op, got '%s'"
76 #define ERR_MISSING_OPERAND "too few operand(s)"
77 #define ERR_EXTRA_OPERAND "extra operand(s) '%s'"
78 #define ERR_DUPLICATE_LABEL "label '%s' previously defined"
79 #define ERR_MISSING_LABEL "label '%s' never defined"
80 #define ERR_BAD_PCOFFSET "PCoffset to '%s' out of range"
81 #define ERR_BAD_IMM "immediate '%s' (bad format)"
82 #define ERR_IMM_TOO_BIG "immediate '%s' out of range"
83 #define ERR_EXPECTED_STR "expected quoted string, got '%s'"
84 #define ERR_BAD_STR "unterminated string '%s'"
85 #define ERR_EXPECTED_FILL "expected .FILL value, got '%s'"
86 #define ERR_BAD_CHAR_CONST "incorrect character constant \"%s\""
87 
90 
93 
95 typedef struct line_info line_info_t;
96 
103 struct line_info {
105  int lineNum;
106  int address;
109  int DR;
110  int SR1;
111  int SR2;
112  int immediate;
113  char* reference;
114 };
115 
139 void asm_error (const char* msg, ...);
140 
159 line_info_t* asm_init_line_info (line_info_t* info, const char* opTok);
160 
165 void asm_print_line_info (line_info_t* info);
166 
168 void asm_init (void);
169 
196 line_info_t* asm_pass_one (const char* asm_file_name, const char* sym_file_name);
197 
215 void asm_pass_two(const char* obj_file_name, line_info_t* list);
216 
220 void asm_term (line_info_t* list);
221 
222 #endif
void asm_init(void)
Definition: assembler.c:73
int SR1
Definition: assembler.h:110
void asm_pass_two(const char *obj_file_name, line_info_t *list)
Definition: assembler.c:84
Defines the interface to symbol.c functions (do not modify)
Definition: lc3.h:161
#define LC3AS_VAR
Definition: assembler.h:59
void asm_print_line_info(line_info_t *info)
Definition: assembler.c:52
int lineNum
Definition: assembler.h:105
int address
Definition: assembler.h:106
opcode_t opcode
Definition: assembler.h:107
void asm_term(line_info_t *list)
Definition: assembler.c:88
line_info_t * asm_init_line_info(line_info_t *info, const char *opTok)
Definition: assembler.c:33
enum opcode opcode_t
char * reference
Definition: assembler.h:113
LC3AS_VAR int numErrors
Definition: assembler.h:89
line_info_t * asm_pass_one(const char *asm_file_name, const char *sym_file_name)
Definition: assembler.c:77
line_info_t * next
Definition: assembler.h:104
int DR
Definition: assembler.h:109
Definition: assembler.h:103
LC3AS_VAR int printPass1
Definition: assembler.h:92
inst_format_t * format
Definition: assembler.h:108
int immediate
Definition: assembler.h:112
definitions of the LC3 instruction set architecture (ISA) (do not modify)
int SR2
Definition: assembler.h:111
void asm_error(const char *msg,...)
Definition: assembler.c:62