[SOLVED] SOLVED:Final Project: LC-3 Simulator

35.00 $

Programming resource
Digital learning resource
Category:
Practical programming resource
Suitable for guided study and reference
Tutor guidance available when needed

Description

5/5 - (3 votes)

A.Why? • Implementing a computer really helps you understand its structure. B.Outcomes After this project, you should • Know how to implement the major parts of a computer in a higher-level language. • Know how to access structures via pointers in C. C.Project • You are to implement of a simple simulator for the LC-3 in C. As in the simulator you did for the Simple Decimal Computer, you will be given a skeleton of the program; your job is to complete the implementation. • Once again, the user interface will be console-oriented. Instead of typing in the program, however, the user will be able to read the program to be executed. • This is an individual project. • Your program should: • Prompt for and read the name of an input file and then read the input file to initialize memory (see below). • Run a command loop to execute the program or dump registers/memory. D.Input File • You should prompt the user for a file name (complain if the file doesn’t exist). Use input.hex as the default filename. (If you can’t get the prompting to work correctly, at least read from input.hex.) • The file should be a *.hex file (the kind produced by the LC-3 editor on assembling a *.asm file). A *.hex file is a sequence of lines with a four-digit hex number on each line (no leading x or 0x). The first line specifies the .ORIG to load the program to. The remaining lines comprise the program. E.g., Assembler File Hex file ORIG x3000 3000 LD R1, X 2203 ADD R1, R1, 1 1261 ST R1, X 3201 HALT F025 X .FILL 17 0011 .END • The rest of memory should be initialized to zeros except for the last location, which should be initialized to a HALT instruction. (The textbook’s LC3 simulator causes an error if you execute that location.) E.The Command Loop • Once the program is read into memory, initialize the program counter (to the .ORIG value), set the IR to all 0’s, the condition code to Z, and start a command loop. There are five commands. The user should enter a carriage return after each command (so h <cr, for example). • h for help: Print a summary of the simulator commands. • d for dump control unit: Print out the program counter, instruction register, condition code, and data registers. • m n₁ n₂ for memory: Print out the values of memory at locations n₁, n₁+1, …, n₂. (If n₁  n₂, then no values get printed out.) The values n₁ and n₂ should be in hex with a leading x. Don’t print out the value of a location if the value is zero. If n₁ or n₂ is an illegal address, print an error message and skip the memory dump.
• An integer: Run that number of instruction cycles (but stop early if you execute a HALT). If the machine is already halted, say so but don’t run any instruction cycles. • No input, just • For LD reg, offset, you say which register you’re loading, the offset value, the PC + offset address, and the value at M[PC + offset] you’re copying to the register. • The output contains all the same information as the sample solution’s output. Minor differences like spacing and case and what order you print things on a line aren’t relevant. • The code should be commented, readable, with good-sized routines (don’t have just a main program hundreds of lines long; each routine should do one conceptual thing). • For a grade of “B” • The program compiles to an executable, though there may be warnings. • The simulator commands h, r, m, <integer, and q should work, though the m command might not do everything it should (check for bad addresses, avoid printing zeros, etc). • The simulator has words of the right length, but it may get confused about overflow and truncation from int to short int etc. • The simulator always reads its hex input from the file input.hex (it doesn’t prompt for a name, or it handles the name incorrectly and reads from input.hex instead). • 75% of the opcodes should be implemented. (This can range from 75% of the opcodes completely working to all the opcodes 75% working.) Each TRAP counts as a different opcode. • The code is mostly commented, mostly readable, and there may be a bit of imbalance in routine sizes (but again, not just a main program hundreds of lines long). • For a grade of “C” • As for a grade of “B” but only 33% – 74% of the opcodes are implemented. • The m command doesn’t support (or ignores) the memory limit values. (But m

Resource details

Understand the Task Before You Use the Resource

Review the requirements, identify the programming concepts involved, study the implementation and test your understanding with your own examples and modifications.