Functions | Variables
util.c File Reference

You will modify this file and implement the util.h interface. More...

#include <strings.h>
#include <stdlib.h>
#include <ctype.h>
#include "util.h"

Functions

name_val_tutil_bin_search (name_val_t map[], int numNames, const char *name)
 
opcode_t util_get_opcode (const char *name)
 
bool util_is_valid_label (const char *s)
 
int util_get_reg (const char *regStr)
 
int util_parse_cond (const char *condCodeStr)
 
bool util_get_int (const char *token, int *value)
 

Variables

static name_val_t lc3_instruction_map []
 
static int numOps = 0
 
static name_val_t register_map []
 
static int numRegisters = sizeof(register_map) / sizeof(register_map[0])
 

Detailed Description

This is a implementation of the interface that you will write for the assignment.

Author
your name here

Function Documentation

name_val_t* util_bin_search ( name_val_t  map[],
int  numNames,
const char *  name 
)
Todo:
implement this function
bool util_get_int ( const char *  token,
int *  value 
)
Todo:
implement this function
opcode_t util_get_opcode ( const char *  name)
Todo:
implement this function
int util_get_reg ( const char *  regStr)

This is an example of how to use the binary search routine

bool util_is_valid_label ( const char *  s)
Todo:
implement this function
int util_parse_cond ( const char *  condCodeStr)
Todo:
implement this function

Variable Documentation

name_val_t lc3_instruction_map[]
static
Initial value:
= {
{ ".BLKW", OP_BLKW },
{ "TRAP", OP_TRAP }
}
Definition: lc3.h:86
Definition: lc3.h:83
Todo:
complete the initializtion of this data structure A sorted list of all the opcode names the assembler might see. There are more entries than there are opcodes because some LC3 instructions have multiple forms. These include JSR/JSRR, RET/JMP, the eight BR instructions and various pseudo-ops. In other implementations, this might be a hash table or a BST.
int numOps = 0
static
Todo:
initialize this value
int numRegisters = sizeof(register_map) / sizeof(register_map[0])
static

This is an example of how to let the compiler figure out how many entries there are.

name_val_t register_map[]
static
Initial value:
= {
{ "R0", 0},
{ "R1", 1},
{ "R2", 2},
{ "R3", 3},
{ "R4", 4},
{ "R5", 5},
{ "R6", 6},
{ "R7", 7},
}

This is an example of how to initialize an array of structs