Fall 1999 COMP 222 Peter Smith

Handout #4

Programming project - part 2

Due date: Thursday, 4 October, 2001

Add to your part 1 of your program an integer function called load.

The load function reads data in hexadecimal from a file into your representation of memory. The

user specifies the name of the file at run-time when the function is called. The format of a load file is as follows (each letter represents a hex digit):

aaa

bbb

ccc

dd

.

.

.

.

dd

ee

aaa - the load address - where the first byte of the program will be stored in memory

bbb - the byte count - count of bytes that will be loaded to memory

ccc - start address - where program will be started - save for later

dd - byte to be read into the memory array

ee - checksum. Total of all the dd plus ee should be a multiple of 256.

Error checking

The load function should perform checks on the values in the file and if there is an error

condition (for example load address + byte count > MEMSIZE, start address out of range, invalid input, checksum error) it should output an error message and return 0. If the loading is successful then the function should return 1.

The function should return (via the parameter list) the values of the load address, the byte count

and the start address.

C language features

File opening and closing, reading from a file, passing values back through parameter list

Turn in a listing of your program including the new function together with the results of testing

it. You should ensure that your testing demonstrates each of the error conditions that you check

for. If a call of load is successful you should use display to show the relevant parts of the memory array.

Grading: Correctness 50

Testing 30

Readability 20