My Project
Functions
assembler.c File Reference

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_tasm_init_line_info (line_info_t *info)
 
void asm_print_line_info (line_info_t *info)
 
void asm_error (const char *msg,...)
 
void asm_init (void)
 
line_info_tasm_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)
 

Detailed Description

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.

Author
your name here

Function Documentation

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.

Parameters
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  )
Todo:
implement this function
line_info_t* asm_init_line_info ( line_info_t info)

A function to initialize all the fields of the structure to default values. The fields info->lineNum and info->address are initialized from global values defined in assembler.c.

Parameters
info- pointer to information about a source line. If the value is NULL, memory for the structure is dynamically allocated.
Returns
the initialized structure
line_info_t* asm_pass_one ( const char *  asm_file_name,
const char *  sym_file_name 
)
Todo:
implement this function
void asm_pass_two ( const char *  obj_file_name,
line_info_t list 
)
Todo:
implement this function
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.

Parameters
info- pointer to informaton about a source line
void asm_term ( line_info_t list)
Todo:
implement this function