DOC PREVIEW
UCSD CSE 141L - Lab 2

This preview shows page 1 out of 4 pages.

Save
View full document
View full document
Premium Document
Do you want full access? Go Premium and unlock all 4 pages.
Access to all documents
Download any document
Ad free experience
Premium Document
Do you want full access? Go Premium and unlock all 4 pages.
Access to all documents
Download any document
Ad free experience

Unformatted text preview:

Summer 2005 CSE 141L Projects in Computer Architecture Lab 2: Construct Assembler & Instruction Set Simulator Reports are due at the beginning of class on Tuesday, July 11th. In this lab, you will design an Assembler and an Instruction Set Simulator (ISS) for the 8-bit processor architecture you developed in Lab 1. You will assemble the three programs you developed in Lab 1 using the assembler and then run the three programs on the ISS, ensuring that they function correctly. This lab also has a homework assignment as specified below. What you will turn in for this Lab Written Report Only: • Summary of your ISA from Lab 1, including any changes you might have made. • Static and dynamic instruction count for each one of the three programs. • Answers to the questions below. Written Report & Electronic Turn-in: • Three assembly files annotated with machine code generated by your Assembler, as well as the .imi files for the three programs. • A complete instruction trace for the three programs executing correctly on the ISS. • A memory dump of D-Mem before and after running each one of the three programs. Electronic Turn-in Only: • Complete code for your Assembler, including all header files. • Complete code for your ISS, including all header files. • A makefile for compiling your Assembler and ISS. Alternatively, you must provide instructions on how to compile these programs. Implementation of the Assembler You may write your Assembler in C, C++, Java or as a Perl script. For a description of the input assembly file, see the Lab 1 project specifications. Following are the requirements for the assembler: • Your assembler executable should be named assembler and should be able to be invoked on the command line by itself. The only exceptions are Assemblers coded in Java, which require the Java interpreter to accompany the executable name. • Your assembler should take two (2) command line arguments. The first argument is the input assembly file and the second argument is the output file annotated with the machine code. e.g. assembler mean.s mean.dis (for c/c++/perl programs) e.g. java assembler mean.s mean.dis (for java programs) • Before running the assembler program on your assembly code, you should remove the hand generated machine code from it.2 • The machine code is the hexadecimal encoding of your assembly code. This 2 digit hex code will be inserted at the beginning of each assembly instruction line in your .s file to generate the corresponding .dis file. • The assembler should generate a corresponding .imi file by default. e.g. For above command line, mean.imi will be generated that has only the hex machine code, formatted one instruction per line. • The assembler should be able to parse the required fields (instruction mnemonic, operand(s)), as well as the optional label and comment fields. • The assembler should generate the machine code as well as the program counter (PC) for each instruction. The PC should start at 0x0. Your assembler must compile and run on ieng9.ucsd.edu for credit. No exceptions. Implementation of the Instruction Set Simulator (ISS) You may write your ISS in C++ or Java (C is OK too, with suitable modifications to the instructions below). You should define a class (e.g. Proc) whose members are the resources of the processor (e.g. program counter, registers, instruction memory, data memory, etc.). You should define following methods: • loadIMem(): Reads a text file with hex machine code for your program and loads the instruction memory (I-Mem) starting from location 0. • loadDMem(): Reads a text file with data for your program and loads the data memory (D-Mem) starting from location 0. • reset(): Initializes the internal state of your processor (e.g. sets PC to address 0). • runLoop(): Executes instructions. This function may take an argument for number of instructions to simulate. This will enable you to advance the simulation by a suitable number of instructions, including single stepping. HALT instruction would stop execution of the program. RunLoop() needs to perform the following steps: 1. Fetch: Read 8 bits from I-Mem at location pointed to by the current value of PC. 2. Decode: Analyze the fetched instruction and find opcode and other fields, such as, register(s), immediate data, branch offset, etc. Read operand(s) from register(s) (if any). 3. Execute: Do the ALU operation specified by the instruction. D-Mem may be read during this step. The result of the instruction is either the output of the ALU or the data read from D-Mem. If the instruction is a control-transfer instruction (e.g. a conditional branch) determine whether it is taken or not. 4. Memory/Register Writeback: Write the result produced in Execute step above to the destination specified by the instruction, which may be a register and/or D-Mem. 5. Set Next PC: If the instruction is not a branch, or branch not taken, set PC to PC+1. Otherwise set PC to the target of the branch. 6. Generate instruction trace. For each instruction, you should print the disassembled instruction, which looks exactly like an instruction in your assembly file. In addition, it shows the values read for the operands from the register file and the effective address in the case of memory load or store instruction. You may include any additional information that may be useful for you to debug the programs. 7. Go back to step 1 and continue processing until HALT instruction is encountered.3 • dumpIMem(): Dump contents of I-Mem. It may take arguments for the start and end memory locations and may be used for debugging your program. • dumpDMem(): Dump contents of the D-Mem. It may take arguments for the start and end memory locations and may be used to inspect the contents of the data memory before, during and after execution of a program. • main(): You would make an instance of your class, load I-Mem as well as D-Mem, reset the processor and go through the run loop. At the end of the simulation, ISS should output the dynamic instruction count for the complete program. You should also dump the contents of the data memory before and after execution of the program to show that the results of the program are correct. In main(), you must implement a command level interface that would receive input commands from the user and carry out specific functions, such as: advance the simulation by N instructions, dump memory contents in a given


View Full Document

UCSD CSE 141L - Lab 2

Download Lab 2
Our administrator received your request to download this document. We will send you the file to your email shortly.
Loading Unlocking...
Login

Join to view Lab 2 and access 3M+ class-specific study document.

or
We will never post anything without your permission.
Don't have an account?
Sign Up

Join to view Lab 2 2 2 and access 3M+ class-specific study document.

or

By creating an account you agree to our Privacy Policy and Terms Of Use

Already a member?