C代写:COMPSCI210 LC-3 Assembly

代写LC-3的编译器,将LC-3 assembly language编译成Machine code,作业提供了test集方便查错。

Propersal

This assignment aims to give you some experience with C programming.

Important Notes

  • There are subtle differences between various C compilers. We will use the GNU compiler gcc. Therefore, you MUST ensure that your submissions.
  • Markers will compile your program using command “gcc -o name name.c” where name.c is the name of the source code of your program, e.g. part1.c. That is, the markers will NOT use any compiler switches to supress the warning messages.
  • Markers will use machine code that is different from the examples given in the specifications when testing your programs.

In this assignment, you are required to write C programs to implement some of the functions of the LC‐3 assembler. That is, the programs covert LC‐3 assembly instructions to machine code.

Part 1

In this part of the assignment, you are required to write a C program to translate LC‐3’s AND and ADD assembly language instructions into machine code. The detailed requirements are as below:

  1. The assembly instructions are stored in a file. Each line of the file stores exactly one instruction. The name of the file should be provided to the program as a command line argument.
  2. For this part, it should be assumed that the operands of the instructions only use the “register” addressing mode. That is, the values of all the operands are stored in registers.
  3. It should be assumed that (a) the instructions are valid AND or ADD instructions, (b) there is exactly one space separating the opcode and the operands of the instruction, (c) the operands are separated by exactly one comma “,”, and, (d) all the characters in the instruction are lower case letters.
  4. The machine code of each instruction should be stored as a 16 bits value. Data type “unsigned short” can be used to hold a 16 bits value.
  5. The machine code of each instruction should be displayed as a 4‐digit hexadecimal number.
  6. Name this program as part1.c

Here is an example of the execution of the program. In this example, the name of the file containing the instructions is source1 (the markers will probably use a file with a different name and contents). The contents of source1 are:

add r1,r2,r3
and r0,r4,r5

The execution of the program is shown below. The command line argument is marked in red.

$ ./part1 source1
1283
5105

Part 2

Expand your program in Part 1 to allow the operand use the “immediate” addressing mode. That is, the value of an operand is stored in the instruction. It should be assumed that the value operand is given as a decimal number.
Name this program as part2.c.
Here is an example of the execution of the program. In this example, the name of the file containing the instructions is source2. The contents of source2 are:

add r1,r2,r3
and r0,r4,r5
add r6,r7,-9
and r0,r1,15

The execution of the program is shown below. The command line argument is marked in red.

$ ./part2 source2
1283
5105
1df7
506f

Part 3

Expand your program in Part 2 to allow instruction JMP to be converted.
Name this program as part3.c.
Here is an example of the execution of the program. In this example, the name of the file containing the instructions is source3. The contents of source3 are:

add r1,r2,r3
and r0,r4,r5
jmp r5
add r6,r7,-9
and r0,r1,15

The execution of the program is shown below. The command line argument is marked in red.

$ ./part3 source3
1283
5105
c140
1df7
506f

Part 4

Expand your program in Part 3 to allow instruction LD to be converted.

  • It should be assumed that the symbol table of the assembly language program is stored in a file. Each line of the file contains a symbol and its corresponding address. The symbol and its address are separated by exactly one space. It should be assumed that the address is a hexadecimal number.
  • The name of the file containing the symbol table should be provided as the second command line argument of the program.
  • The starting address of the program should be given as the third command line argument of the program.
  • Name this program as part4.c.

Here is an example of the execution of the program. In this example, the name of the file containing the instructions is source4. The contents of source4 are:

add r1,r2,r3
and r0,r4,r5
jmp r5
ld r2,abc
ld r6,def
add r6,r7,-9
and r0,r1,15

The name of the file containing the symbol table is stable4. The contents of stable4 are:

abc 3011
def 3000 

The execution of the program is shown below. The command line arguments are marked in red.

$ ./part4 source4 stable4 300a
1283
5105
c140
2403
2df1
1df7
506f

Part 5

Expand your program in Part 4 to allow instruction BR to be converted.
Name this program as part5.c.
Here is an example of the execution of the program. In this example, the name of the file containing the instructions is source5. The contents of source5 are:

add r1,r2,r3
and r0,r4,r5
jmp r5
brnp x
ld r2,abc
brz y
ld r6,def
add r6,r7,-9
and r0,r1,15

The name of the file containing the symbol table is stable5. The contents of stable5 are:

abc 3013
def 3000
x 300a
y 3012 

The execution of the program is shown below. The command line arguments are marked in red.

$ ./part5 source5 stable5 300a
1283
5105
c140
0bfc
2404
0402
2def
1df7
506f

Part 6

The answer to this part should be saved in a PDF file named part6.pdf.
Which part of this assignment is the most difficult one for you? Briefly describe your reasons.