乐趣区

关于后端:EECS-370模拟器

Project 1 EECS 370 (Fall 2023)Worth: 100 points

0. Starter Code

starter_1a.tar.gz files DescriptionMakefile Makefile to compile the projectspec.as Spec test case assembly filespec.mc.correct Correct machine code output for spec test casestarter_assembler.c Starter code for the LC-2K assemblerstarter_1s.tar.gzfilesDescriptionMakefile Makefile to compile the projectspec.mcSpec test case machine code file, this is the same as spec.mc.correctfrom P1Aspec.out.correct
Correct output for spec test case – note that your simulator should
write to standard outstarter_assembler.c Starter code for the LC-2K simulatorThere is no starter code for project 1M, the assembly multiplication program.Feel free to use wget and tar as follows:Try clicking the line numbers to copy terminal commands!$ wgethttps://eecs370.github.io/project_1_spec/starter_1a.tar.gzSaving to:‘starter_1a.tar.gz’terminal

1. Purpose

This is a 3 part project where you will be coding the following:Project Description Required File(s) for Submission1A – The LC2KAssemblerFor project 1A, you will write a cprogram which takes as input anLC2K assembly file (denoted with.as ) and outputs its correctmachine code representation into amachine code file (denoted with.mc )assembler.c, and a suite of testassembly files ending in *.as tobe ran against your assembler, andbuggy instructor assemblers1S – The LC2KSimulatorFor project 1S, you will write acprogram which simulates the LC2KISA, with a given machine code file
as input. It will output the simulationto stdoutsimulator.c, and a suite of testassembly files ending in *.as .These test files will first beassembled by the instructorassembler, and then ran againstyour simulator, and buggyinstructor simulators.starter_1a.tar.gz 100% [==============>]

$ tar -xvzf starter_1a.tar.gz
starter_1a/
starter_1a/spec.as
starter_1a/spec.mc.correct
starter_1a/Makefile
starter_1a/starter_assembler.c
$ wget https://eecs370.github.io/project_1_spec/starter_1s.tar.gz
Saving to:‘starter_1s.tar.gz’starter_1s.tar.gz 100% [==============>]
$ tar -xvzf starter_1s.tar.gz
starter_1s/
starter_1s/spec.mc
starter_1s/spec.out.correct
starter_1s/Makefile
starter_1s/starter_simulator.c

Project Description Required File(s) for Submission1M – LC2K
AssemblyMultiplicationFor project 1M you will write an LC2K
assembly program which multipliestwo positive 15 bit numbers.mult.as

2. LC-2K Instruction Set Architecture

Before we dive into project specifics, it is important to understand the LC2K (Little Computer 2000)Instruction Set Architecture. As for this and several of the future projects, you will be gradually“building”out the LC-2K toolchain and LC-2K simulators. TheLC-2K instruction set is very simple,but it is general enough to solve complex problems. To complete project 1’s three parts, you willneed to only know the LC-2K Instruction Set Architecture.In general, an instruction set architecture defines how a programmer can use the processor, andwhat operations the processor supports.
The LC-2K ISA is a RISC architecture (Reduced Instruction SetComputer): This means that itsupports simpler operations. Note that the ISA defines both the assembly language and the machinecode. An assembly language is a low level programming language that closely relates to theunderlying machine code. Each line of assembly code can be assembled into 1 line of machine Pro tip: LC2K assembly files (.as ) and LC2K machine code files (.mc ) are plain-textfiles, meaning you should be able to edit and view them in a text editor.LC2K assembly files can also use the (.s ) and (.lc2k )file extensions. This is helpful forstudents who use XCode and cannot open (*.as) files Important facts about the LC-2K ISA:
There are 8 registers (registers 0 through 7)Each address is 32-bits
Each address stores a word (a word is 4 bytes which is also 32 bits)LC-2K has 65536 words of memoryBy assembly-language convention register 0 always has a value of 0This is technically not enforced, but no assembly language program should changeegister 0 from its initial value of 0).code, which looks like a bunch of numbers. The machine code is a representation of assemblycode, which is usable by the computer.The machine code file contains the actual values stored in memory (that is, the assembledassembly code). Specifically weassume that the first line of the machine code file represents the
0th address. Our assembly language also supports the use of symboliclinks, and assemblerdirectives. These higher-level operations specify how the assembler should handle the inputassembly language and are not visible in the machine code translation after assembly.
When used with a beq instruction, a label indicates you want to branch to that label’saddress.When a label is used inplace of a number in field0 for a .fill assembler directive, you areto resolve the label’s value, and use that value for the fill.Take a look at the spec example for project 1A:spec.as – lines with label definitions are highlightedNotice how we define the labels start , done , five , neg1 , and stAddr . Remember fromsection 2.2 that each line of assembly represents an address. Thus we say the following:lw 0 1 five load reg1 with 5 (symbolic address)lw 1 2 3 load reg2 with -1 (numeric address)start add 1 2 1 decrement reg1beq 0 1 2 goto end of program when reg1==0beq 0 0 start go back to the beginning of the
stAddr .fill start will contain the address of start (2)
The label start resolves to a value of 2, since it is defined on the
An LC-2K machine code file (*.mc) is made up of multiple lines decimal numbers. Each line of themachine code file represents the number stored at that address in the memory. For example, the
first line of the machine code file represents the value of address 0 when the program begins.Bits 31-25 are unused for all instructions, and should always be 0. Bit 0 is the least-significant bit.

R-type instructions (add ,nor)
bits 24-22: opcode
bits 21-19: reg A
bits 18-16: reg B
bits 15-3: unused (should all be 0)
bits 2-0: destReg
I-type instructions (lw ,sw , beq)
bits 24-22: opcode
bits 21-19: reg A
bits 18-16: reg B
bits 15-0: offsetField (a 16-bit, 2’s complement number with
a range of -32768 to 32767)J-type instructions (jalr)
bits 24-22: opcode
bits 21-19: reg A
bits 18-16: reg B
bits 15-0: unused (should all be 0)O-type instructions ( halt ,
noop )
bits 24-22: opcode
bits 21-0: unused (should all be 0)

3. LC-2K Assembly Language and Assembler

The first part of this project is to write a program to take an assembly-language program andtranslate it into machine language. You will translate assembly-language names for instructions,
such as beq, into their numeric equivalent (e.g. 100), and you will translate symbolic names foraddresses into numeric values. The final output will be a series of 32-bit instructions (instruction bits31-25 are always 0).The assembler should make two passes over the assembly-language program. In the first pass, itwill calculate the address for every symbolic label. Assume that the first instruction is at address 0.In the second pass, it will generate a machine-language instruction (in decimal) for each line ofassembly language. For example, here is an assembly-language program (that counts down from 5,stopping when it hits 0).spec.asAnd here is the corresponding machine language:
spec.as’s corresponding machine language, with addresses and hex |
Note: All instructions should appear before any .fill’s.Instructions and .fill’s should not beinterleaved. e.g. Your assembly programs should look like this:Correct usage of .fillThey should NOT look like this: Hints: The spec assembly-languageprogram is a good case to include in your test suite,though you’ll need to write more test cases to get full credit. Remember to create some testcases that test the ability of an assembler to check for the errorsin Section 3.3.
Incorrect usage of .fillThis won’t be enforced for project 1, but assembly programs with interleaved instructions and.fill’s will not work properly in project 2. Note that many students like to reuse their project 1assembly tests for project 2.Since offsetField is a 2’s complement number, it can only store numbers ranging from -32768 to32767. For symbolic addresses, your assembler will compute offsetField so that the instruction

退出移动版