Part 1 (35 marks)
LC3Edit is used to write LC‐3 assembly programs. After a program is written, we use the LC‐3 assembler (i.e. the “Translate Assemble” function in LC3Edit) to convert the assembly program into binary executable. The binary executable being generated by LC3Edit is named “file.obj” where “file” is the name of the assembly program (excluding the “.asm” suffix). In this specification, a “word” refers to a word in LC‐3. That is, a word consists of two bytes. The structure of the “file.obj” is as below:
- The first word (i.e. the first two bytes) is the starting address of the program.
- The subsequent words correspond to the instructions in the assembly program and the contents of the memory locations reserved for the program using various LC‐3 directives.
- In LC‐3, data are stored in Big‐endian format (refer to https://en.wikipedia.org/wiki/Endianness to learn more about Big‐endian format). For example, if byte 0x12 in word 0x1234 is stored at address 0x3000, byte 0x34 is stored at address 0x3001. This means, when you read a sequence of bytes from the executable of an LC‐3 assembly program from a file, the most significant bit of each word is read first.
In this part of the assignment, you are required to write a C program to display each word in the “.obj” file of a program in hexadecimal form. That is, the C program should display each binary number stored in the “.obj” file in it corresponding hexadecimal form.
- Name the C program as “part1.c”.
- The name of the “.obj” file (the name of the file INCLUDES the “.obj” suffix) must be given as a command line argument. The number of instructions in the file is NOT limited.
- In the output, each line shows the contents of one word.
- The value of each word must have a “0x” prefix.
- The letter digits “a” to “f” must be shown as lowercase letters.
Part 2 (46 marks)
In this part, you are required to write a C program to implement a LC‐3 simulator that is capable of executing instruction “LD”.
- Name the C program as “part2.c”.
- The name of the “.obj” file (the name of the file INCLUDES the “.obj” suffix) must be given as a command line argument. The number of instructions in the file is NOT limited.
- The state of the simulator consists of the contents of the 8 general purpose registers (i.e. R0 to R7), the value of the program counter (i.e. PC), the contents of the instruction register (i.e. IR), and the value of the condition code (i.e. CC).
- The values in R0 to R7, PC and IR should be shown as hexadecimal value. The value of CC is either N, Z or P.
- Before the simulator starts executing a program, it should first display the initial state of the LC‐3 machine. In the initial state, R0 to R7 and IR should all be 0; PC should be the starting address of the program to be executed; and CC should be set to Z.
- When displaying the value of R0 to R7, PC, IR and CC, a tab character (denoted as “t” in C) is used to separate the name of the register and the value of the register.
- Each hexadecimal value must have a “0x” prefix. The letter digits “a” to “f” must be shown as lowercase letters.
- After showing the initial state, the simulator should execute each instruction except the “HALT” pseudo instruction in the “.obj” file. For this part, the simulator should display the hexadecimal code of each LD instruction that has been executed and the state of the LC‐3 machine after each LD instruction is executed. The hexadecimal code of an instruction is the hexadecimal form of the 16 bits used to represent the instruction. The hexadecimal code of each LD instruction should be preceded with “after executing instructiont” (where t denotes a tab character) and “0x”.
- The simulator should output a line consisting of 18 “=” after displaying the state of the LC‐3 machine.
- When the execution reaches the “HALT” instruction, the simulator terminates.
Part 3 (3 marks)
This part is based on Part 2.
- Name this program as part3.c
- Expand the functionality of the simulator in part 2 to allow the simulator to execute instruction “LEA”.
- For this part, the simulator should display the hexadecimal code of each LEA instruction that has been executed and the state of the LC‐3 machine after each LEA instruction is executed. The hexadecimal code of each LEA instruction should be preceded with “after executing instructiont” (where t denotes a tab character) and “0x”.
- The simulator should output a line consisting of 18 “=” after displaying the state of the LC‐3 machine.
Part 4 (3 marks)
This part is based on Part 3.
- Name this program as part4.c
- Expand the functionality of the simulator in part 3 to allow the simulator to execute instruction “LDI”.
- For this part, the simulator should display the hexadecimal code of each LDI instruction that has been executed and the state of the LC‐3 machine after each LDI instruction is executed. The hexadecimal code of each LDI instruction should be preceded with “after executing instructiont” (where t denotes a tab character) and “0x”.
- The simulator should output a line consisting of 18 “=” after displaying the state of the LC‐3 machine.
Part 5 (3 marks)
This part is based on Part 4.
- Name this program as part5.c
- Expand the functionality of the simulator in part 4 to allow the simulator to execute instruction “AND”.
- For this part, the simulator should display the hexadecimal code of each AND instruction that has been executed and the state of the LC‐3 machine after each AND instruction is executed. The hexadecimal code of each AND instruction should be preceded with “after executing instructiont” (where t denotes a tab character) and “0x”.
- The simulator should output a line consisting of 18 “=” after displaying the state of the LC‐3 machine.
Part 6 (3 marks)
This part is based on Part 5.
- Name this program as part6.c
- Expand the functionality of the simulator in part 5 to allow the simulator to execute instruction “NOT”.
- For this part, the simulator should display the hexadecimal code of each NOT instruction that has been executed and the state of the LC‐3 machine after each NOT instruction is executed. The hexadecimal code of each NOT instruction should be preceded with “after executing instructiont” (where t denotes a tab character) and “0x”.
- The simulator should output a line consisting of 18 “=” after displaying the state of the LC‐3 machine.
Part 7 (3 marks)
This part is based on Part 6.
- Name this program as part7.c
- Expand the functionality of the simulator in part 7 to allow the simulator to execute instruction “ADD”.
- For this part, the simulator should display the hexadecimal code of each ADD instruction that has been executed and the state of the LC‐3 machine after each ADD instruction is executed. The hexadecimal code of each ADD instruction should be preceded with “after executing instructiont” (where t denotes a tab character) and “0x”.
- The simulator should output a line consisting of 18 “=” after displaying the state of the LC‐3 machine.Part 8 (3 marks)
This part is based on Part 7.
- Name this program as part8.c
- Expand the functionality of the simulator in part 7 to allow the simulator to execute instruction “BR”.
- For this part, the simulator should display the hexadecimal code of each BR instruction that has been executed and the state of the LC‐3 machine after each BR instruction is executed. The hexadecimal code of each BR instruction should be preceded with “after executing instructiont” (where t denotes a tab character) and “0x”.
- The simulator should output a line consisting of 18 “=” after displaying the state of the LC‐3 machine.Part 9 (1 mark)
1 mark for having no compile warning messages for all the submitted programs.
Do you need help with this assignment or any other? We got you! Place your order and leave the rest to our experts.