Hello, dear friend, you can consult us at any time if you have any questions, add WeChat: THEend8_
Total marks: 100
This assignment aims to give you some experience with C programming and to help you gain
better understanding of the instruction format of LC‐3.
Important Notes:
There are subtle differences between various C compilers. We will use the GNU compiler gcc
on login.cs.auckland.ac.nz for marking. Therefore, you MUST ensure that your submissions
compile and run on login.cs.auckland.ac.nz. Submissions that fail to compile or run on
login.cs.auckland.ac.nz will attract NO marks.
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 instructions that are different from the examples given in the specifications
when testing your programs.
The files containing the examples can be downloaded from Canvas and unpacked on the
server with the command below:
o tar xvf A3examplefiles.tar.gz
As we need to return the assignment marks before the exam of this course, there is NO
possibility to extend the deadline for this assignment. NO late assignment will be accepted.
Academic Honesty
Do NOT copy other people's code (this includes the code that you find on the Internet).
We will use Stanford's MOSS tool to check all submissions. The tool is very "smart". Changing
the names of the variables, shuffling the statements around and inserting dummy statements
will not fool the tool. In previous years, quite a few students had been caught by the tool; and,
they were dealt with according to the university’s rules at
https://www.auckland.ac.nz/en/about/learning‐and‐teaching/policies‐guidelines‐and‐
procedures/academic‐integrity‐info‐for‐students.html
2
In this assignment, you are required to write C programs to implement some of the functions of
the LC‐3 assembler. That is, the C programs covert LC‐3 assembly instructions to machine code
that can be executed by the LC‐3 simulator.
Part 1 (27 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 a binary executable. The file stores the binary executable is called the object file.
The object file 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 an object file 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 and
https://www.webopedia.com/TERM/B/big_endian.html 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 object file of an LC‐3 assembly program, 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 create an object file that
can be used by the LC‐3 simulator. The detailed requirements are as below:
1. A text file containing some numbers is given. This file is called numbers file. Each
number in the file is a four‐digit hexadecimal number. There is one number in each line
of the file. You can regard each number as a word in LC‐3.
2. Write a program to (a) read the numbers from the numbers file, (b) create an object file
and write the numbers to the object file.
3. The object file is a binary file. It contains a sequence of words (i.e. the numbers from the
numbers file). When the words are stored in the object file, they must be stored in Big‐
endian format. For example, when word 12ab is stored in the object file, 12 (i.e. the
byte containing the most significant bit) is stored in the file before ab.