My Project
Macros | Functions
util.c File Reference

Implement two functions in this file. NOTE: One of the data structures is missing several entries. Add the required entries to that data structure. More...

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

Macros

#define nCond   4
 
#define zCond   2
 
#define pCond   1
 

Functions

name_val_tutil_bin_search (name_val_t map[], int numNames, const char *name)
 
int util_get_opcode (const char *name)
 
int util_is_valid_label (const char *s)
 
int util_get_reg (const char *regStr)
 
int util_parse_cond (const char *ccStr)
 

Detailed Description

Implement two function in this file

Function Documentation

name_val_t* util_bin_search ( name_val_t  map[],
int  numNames,
const char *  name 
)
Todo:
implement this function
int util_get_opcode ( const char *  name)

Get the opcode associated with an LC3 op (e.g. "ADD")

Parameters
name- name of operand
Returns
the opcode for this name, or -1 if the name is not and LC3 operation information about that instruction
int util_get_reg ( const char *  regStr)

Determine if the string represents a valid register specification A register is specified by the letter 'R' (case insesitive) followed by a digit 0 to 7.

Parameters
regStr- the string to check
Returns
the register number if the string is a valid register, or -1 if it is not.
int util_is_valid_label ( const char *  s)
Todo:
implement this function
int util_parse_cond ( const char *  condCodeStr)

Determine the condition code associated with the string. The string consists of of 0 to 3 three characters, with no more that one each character from the set 'nzp' (case insensitive). The values must follow that order. That is, if 'n' is present it MUST proceed 'z' and/or 'p'. If 'z' is present, in must preceed 'p'.

Parameters
condCodeStr- the string to parse (e.g. "zp")
Returns
- the value (1-7) representing the condition code or -1 if the condCodeStr is not valid.