You will modify this file and implement the assembler.h interface. More...
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <strings.h>
#include <stdarg.h>
#include <assert.h>
#include "assembler.h"
#include "lc3.h"
#include "symbol.h"
#include "tokens.h"
#include "util.h"
Functions | |
line_info_t * | asm_init_line_info (line_info_t *info, const char *opTok) |
void | asm_print_line_info (line_info_t *info) |
void | asm_error (const char *msg,...) |
void | asm_init (void) |
line_info_t * | asm_pass_one (const char *asm_file_name, const char *sym_file_name) |
void | asm_pass_two (const char *obj_file_name, line_info_t *list) |
void | asm_term (line_info_t *list) |
Variables | |
static int | srcLineNum |
static int | currAddr |
This is a implementation of the interface that you will write for the assignment. Although there are only four functions defined by the interface, it is likely that you will add many helper functions to perform specific tasks.
void asm_error | ( | const char * | msg, |
... | |||
) |
A function to print error messages. This function takes a minimum of one parameter. It is exaclty like the printf()
function. The first parameter is a formatting string. This will be one of the values defined above that starts with ERR_
.The remaining parameters (if any) are the actual values to be printed (generally a token). The function prints the word ERROR:
and the the value of srcLineNum
along with the information provided by the parameters. It must be used for reporting all errors. After printing the error, the global variable numErrors
is incremented. This function relies on the static variable srcLineNum
in assembler.c
. Suppose one wanted to report that a file could not be opened for reading. The C code might look line this.
FIlE* f = fopen(filename, "r"); if (f == NULL) { asm_error(ERR_OPEN_READ, filename); // any other actions }
Ideally, this function would throw an exception.
msg | - the formating string (one of the ERR_xxx macros) |
... | - a list of values to be substitued into the format string. |
void asm_init | ( | void | ) |
line_info_t* asm_init_line_info | ( | line_info_t * | info, |
const char * | opTok | ||
) |
A function to initialize all the fields of the structure to default values. Since C does not have constructors, it is convenient to write functions to initialize fields of a structure to default values. The first parameter allows the function to be used in two ways. If its value is NULL
, the structure is malloc()
-ed. If it is not NULL
, the structure pointed to by the parameter is initialized. This allow the easy initialization of a local variabe in some other function by passing its address. The fields info->lineNum
and info->address
are initialized from global values defined in assembler.c
. You may modify this function to do additional checks and initialization if you find that usefull. You may not change its signature. This function is only used in assembler.c
and should be static
. It is declared here for documentation purposes.
info | pointer to an existing structure or NULL |
opTok | the string representing the operation (e.g. "ADD" |
line_info_t* asm_pass_one | ( | const char * | asm_file_name, |
const char * | sym_file_name | ||
) |
void asm_pass_two | ( | const char * | obj_file_name, |
line_info_t * | list | ||
) |
void asm_print_line_info | ( | line_info_t * | info | ) |
A function to print the infomation extracted from a source line. This is used for debugging only.
info | - pointer to informaton about a source line |
void asm_term | ( | line_info_t * | list | ) |
|
static |
Global variable containing the current LC3 address
|
static |
Global variable containing the current line number in the source file