My Project
|
Defines interface to utility functions for LC3 assembler (do not modify). More...
#include <stdbool.h>
Go to the source code of this file.
Data Structures | |
struct | name_val |
Typedefs | |
typedef struct name_val | name_val_t |
Functions | |
name_val_t * | util_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 *condCodeStr) |
bool | util_get_int (const char *token, int *value) |
This defines the interface to some utilities for the LC3 assembler. In completing the corresponding .c file, you will learn how to encode information in data structures, rather than directly in "code". You will also learn how to do some simple character processing.
typedef struct name_val name_val_t |
Define a mapping between a name and an integer value
name_val_t* util_bin_search | ( | name_val_t | map[], |
int | numNames, | ||
const char * | name | ||
) |
Search a sorted list of items for a given name. The names are case insensitive, so the name "foo" and "Foo" match. This function is only used in util.c, but is declared here for documentation purposes.
map | - a sorted array of values |
numNames | - number of entries in the array |
name | - the name to search for (case insensitive) |
bool util_get_int | ( | const char * | token, |
int * | value | ||
) |
Convert a string to an integer using the LC3 syntax for constants. The LC3 format assumes hex unless the string is preceeded by a &# sign to indicate decimal values. The initial x/X for hex values is optional. Hex values may be preceeded by a '-'.
token | - the string to be converted |
value | - pointer to where value will be stored |
int util_get_opcode | ( | const char * | name | ) |
Get the opcode associated with an LC3 op (e.g. "ADD")
name | - name of operand |
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.
regStr | - the string to check |
This is an example of how to use the binary search routine
int util_is_valid_label | ( | const char * | s | ) |
Determine if a string is a valid label or not. Valid labels beging with a letter or '_' and may contain only letters, digits and ('_'). You may find the C header ctype.h
useful.
s | - ths string to validate @ return 0 if the string is not valid, non-zero if it is |
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'.
condCodeStr | - the string to parse (e.g. "zp") |