java代写 | Java ATOM Assignment 2

这是一个英国的计算机代写架构作业

1 Introduction

This project represents a substantive programming exercise. Like all work for this class, it is to be completed individually: any form of collaboration is prohibited, as detailed in the syllabus. This project is considered a take home exam.

Before even reading this assignment, please read the E20 manual thoroughly. Read the provided E20 assembly language examples.

2 Assignment: Assembler

Yourtask is to write an E20 assembler: a program that will convert E20 assembly language into E20 machine language.

Each E20 assembly language instruction can be expressed as a 16-bit E20 machine language instruction. The rules for converting between the two forms is given in the E20 manual, particularly the chapter on the E20 instruction set.

For example, consider the assembly language instruction addi $1, $2, 3. The opcode is addi, used for performing addition of an immediate. In this case, we are adding the number 3 to the value currently stored in register $2, and storing the result into register $1. The corresponding machine code instruction is 0010100010000011 in binary, or 59523 in decimal, or e883 in hex. Each component of the assembly language instruction maps onto a region of its machine language counterpart. Below, we color-code each field to show how they match:

addi $1, $2, 3 <==> 0010100010000011

As you can see, the first (most significant) three bits of the machine code instruction correspond to the opcode;the next three bits indicate the source register; the next three bits indicate the destination register; and the last seven bits store the immediate.

Unlike the E15, in the E20, different instructions have different formats, and your program will need to take that into account.

The purpose of your assembler is to make it easier to write programs for the E20 processor. Eventually, we will execute the machine code generated by your assembler on a simulated E20processor.

2.1 Input

The input to your assembler will be the name of an E20 assembly language file, given on the command line. By convention, E20 assembly language files have an .ssuffix.

Your program will read in the contents of the file. You may assume that the file contains well-formed E20 assembly language code. The file may contain comments, which your program should ignore.

You are provided with several examples of valid E20 assembly language files, which you can use to test your assembler.

Here is an example of an E20 assembly language program, in a file named loop2.s:

movi $1 , 10 beginning:
jeq $1 , $0, done addi
$1 , $1 , -1 j
beginning
done:
halt

2.2 Output

Your program should print to stdout the E20 machine code corresponding to its input.

Below is an example invocation of an assembler from Linux’s bash. In this case, we are assembling the assembly language program given above. Text in italics represents a command typed by the user.

user@ubuntu: / e20$./asm.py loop2.s
ram[0] = 16’b0010000010001010; // movi $1 ,10
ram[1] = 16’b1100010000000010; // beginning: jeq $1,$0,done ram[2]
= 16’b0010010011111111; // addi $1,$1,-1
ram[3] = 16’b0100000000000001; // j beginning
ram[4] = 16’b0100000000000100; // done: halt

Your assembler should produce output in exactly the format shown above. That is: for each assembly language instruction, print a line of machine code, consisting of the memory address, followed by an equals sign, followed by a 16-bit binary number in Verilog syntax. Your program is responsible for determining the memory address of each instruction. The instructions should be printed in sequential order of their address. You are not responsible for printing the value of memory addresses that are not specified by theinput.

In the above listing, each line of machine code includes a comment indicating the corresponding assembly language code. Your solution does not need to output the comments. However, outputting comments in this way may be helpful as you debug your program.

Your solution will be checked mechanically, so it is important that your assembler produce machine code output identical to the machine code output above. Please avoid losing points for superficial deviations.

2.3 Testing

Several example assembly code files have been provided for you. Each example file includes, in comments, the expected machine code, as well as the expected execution result. You can use these examples to verify the correctness of your assembler. However, you should not rely exclusively on these examples, as they are not sufficient to exercise every aspect of an assembler. You are therefore expected to develop your own test cases.

2.4 Starter code

You may, but are not required to, use the provided starter code for this assignment, found in the files asm-starter.cpp and asm-starter.py. Please rename them to asm.cppor asm.py, as appropriate.