Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

You may do this homework using any IDE of your choice. Your code must compile and run on CSSGATE as we did for the first

You may do this homework using any IDE of your choice. Your code must compile and

run on CSSGATE as we did for the first homework.

Please place a comment at the top of simulator.c explaining which environment

you used to complete this assignment. Follow the coding and commenting

conventions in the files that you are given. Your program when run as is must

display numbers 9 to 1 and final display of the simulator. We do not want to see

any other output.

Submit a zip file of all your .c and .h files on Canvas. Name it uwnetidSimulator.zip or

uwnetid1uwnetid2Simulator.zip, using your uwnetids. Your names must be in the

header of simulator.c. No late work or email submissions will be accepted.

Simulator Instructions

Download a copy of the incomplete LC3 simulator starter code from Canvas. It

includes the following files:

simulator.c

comp.h and comp.c

bstr.h and bstr.c

BitString: The simulation is based on the datatype BitString. The existing code

provides many functions that can manipulate BitString variables for you and you

dont need to write additional functions.

The BitString functions are not well protected from user errors. For example, the

maximum size of a BitString is 16 bits, but there are no checks for exceeding this

limit. Much of your work will involve converting back and forth between several

related forms of data. Be careful not to confuse a BitString with a C string or an

integer.

A BitString is actually an array of char, but the values in each char are 0 or 1.

There is an associated length member that keeps track of how full the array is

(anywhere from 0 to 16). A C string is an array of char also, but in that case the

values are ASCII values probably the ASCII values of '0' or '1', that is 48 and

49.There is a zero at the end of a C string to mark its termination. It will often be

convenient for you to convert a BitString to its decimal value (i.e. an int) so that

your program can do mathematical operations on it.

Computer: The Computer datatype uses BitStrings to represent the contents of

all registers and memory locations. The memory and register file are treated as

arrays of BitString. To execute a single instruction, you will generally need to pull

a couple BitStrings out of the Computer struct, convert them to int, do some

calculations on the ints, convert the results back into BitStrings and put those

BitStrings back into the Computer struct. By frequently displaying the Computer

struct during development, you can verify that individual instructions are

behaving properly.

Simulator: The file simulator.c includes a short LC3 program in two different

forms, assembly language and binary. This program prints the numbers 9 down

to 1 and halts.

Finish the simulator so that this program is loaded and executed. The required

instructions are ADD, LD, BR, OUT, HALT. To finish the simulation, you will need

to at least do the following:

Add functions to execute the unimplemented instructions (like ADD, LD,

BR, OUT, HALT).

Modify main so that the program is loaded into the computer. Follow the

instructions in main for this. DO NOT call COMP_execute in a loop here.

Modify the execute function in comp.c, so that it executes instructions until

it runs into a HALT instruction.

Write test functions for each instruction and you will be graded on these

test functions.

You can model ADD, LD and BR after the NOT instruction provided. You need to

examine the bits in IR and modify memory, condition codes, registers, and the

PC as the current instruction would if executed by the LC3.

For OUT and HALT, which would normally trigger trap routines, the simulator

should instead perform the required action. In the case of HALT, the execute

function should quit (by exiting its loop) and for OUT, a single character should

appear on the IDE's console based on the ASCII code currently in R0. You will

do this with printf("%c", ....).

Your program does not need to execute any other LC3 instructions, but your

code should be general enough to work with similar assembly programs. You will

note that the amount of memory available in the simulator is quite small - roughly

50 words. This is enough for running simple programs.

If you want to try other programs, the LC3 Edit program will create a .bin file

containing 0/1 strings for any assembly program that you compile. The trap

vector and interrupt vector tables are not included in this simulation. We are also

omitting input/output related hardware such as KBDR/KBSR and DDR/DSR.

As a general strategy, you might execute single-instruction programs to test the

quality of your simulator before testing a multi-line program.

Extra Credit: Implement AND, LDI, STI, LDR, STR in addition to the above

instructions for extra credit 1 point for each instruction implemented. You must

create test functions in simulator.c to test these new functions. You will be

graded on the test functions.

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Programming The Perl DBI Database Programming With Perl

Authors: Tim Bunce, Alligator Descartes

1st Edition

1565926994, 978-1565926998

More Books

Students also viewed these Databases questions

Question

What are some rebuttal cons on the John Rogers Ariel investments

Answered: 1 week ago

Question

What must a creditor do to become a secured party?

Answered: 1 week ago

Question

When should the last word in a title be capitalized?

Answered: 1 week ago