Introduction and Instructions: Assignment CSE 112 Computer Organization
Introduction and Instructions: Assignment CSE 112 Computer Organization
TEST CASES:
We will release some test cases with the assignment so that you can test your implementations.
DEADLINES:
You will have two deadlines for this assignment:
1. The mid evaluation: By this deadline you must have the assembler ready. You will be
tested mostly on the test cases already provided to you with the assignment. However,
We might add some other test cases as well. You will only be evaluated on the
assembler.
2. The final evaluation: By this deadline you must have both the assembler and the
simulator ready. You will be evaluated on a much larger set of test cases this time. You
will also be evaluated on the bonus question at this stage.
The mid evaluation will be worth 20% of your final assignment grade. The final evaluation
will be worth the rest 80% of your final assignment grade. The bonus will be worth 10%
making the total 110%.
GRADING:
Q1 and Q2 are mandatory questions. In Q1 you will have to make an assembler. In Q2 you
have to make a simulator for which detailed information is mentioned in the respective
questions.Q3 is a bonus question.
EVALUATION PROCEDURE:
1. Date for the demo of the mid and final evaluation will be announced in due time.
2. On the day of your demo, a compressed archive of all tests will be shared with you on
the google classroom. This archive will include other test cases as well which will not be
provided to you beforehand.
3. On the day of evaluation, you must
a. Prove that you are not running code written after the deadline by running “git log
HEAD” which prints the date and time of the commit pointed to by the HEAD. You
must also run “git status” to show that you don’t have any uncommitted changes.
b. Prove the integrity of the tests archive by computing the sha256sum of the
archive. To compute the checksum, you can run “sha256sum
<path/to/the/archive>”. The TA will then match the checksum to verify the
integrity.
4. Then you can extract the archive and replace the “automatedTesting/tests” directory.
5. Then you need to execute the automated testing infrastructure, which will run all the
tests and finally print your score.
6. The TA will verify the correctness for the test cases which are supposed to generate
errors. You do not need to run these tests by yourself. The testing infrastructure will do
this automatically for you.
PLAGIARISM
1. Any copying of code from your peers or from the internet will invoke institute Plagiarism
policy.
2. Provide proper references if you're taking your code from some other resource.
Needless to say, if the said code is the main part of the assignment, You will be awarded
0 marks.
3. If you are found indulging in any bad practise to circumvent the above mentioned
evaluation procedure, you will be awarded 0 marks and institute plagiarism policy will be
applied.
ISA description:
Consider a 16 bit ISA with the following instructions and opcodes, along with the syntax of an
assembly language which supports this ISA.
The ISA has 6 encoding types of instructions. The description of the types is given later.
where reg(x) denotes register, mem_addr is a memory address (must be an 8-bit binary
number), and Imm denotes a constant value (must be an 8-bit binary number).
The ISA has 7 general purpose registers and 1 flag register. The ISA supports an address size
of 8 bits, which is double byte addressable. Therefore, each address fetches two bytes of
data. This results in a total address space of 512 bytes. This ISA only supports whole
number arithmetic. If the subtraction results in a negative number; for example “3 - 4”, the reg
value will be set to 0 and overflow bit will be set. All the representations of the number are
hence unsigned.
The registers in assembly are named as R0, R1, R2, ... , R6 and FLAGS. Each register is 16
bits.
Note: “mov reg $Imm”: This instruction copies the Imm(8bit) value in the register’s lower 8
bits. The upper 8 bits are zeroed out.
Example:
Suppose R0 has 1110_1010_1000_1110 stored, and mov R0 $13 is executed.
The final value of R0 will be 0000_0000_0000_1101.
FLAGS semantics
The semantics of the flags register are:
● Overflow (V): This flag is set by add, sub and mul, when the result of the operation
overflows. This shows the overflow status for the last executed instruction.
● Less than (L): This flag is set by the “cmp reg1 reg2” instruction if reg1 < reg2
● Greater than (G): This flag is set by the “cmp reg1 reg2” instruction if the value of
reg1 > reg2
● Equal (E): This flag is set by the “cmp reg1 reg2” instruction if reg1 = reg2
The default state of the FLAGS register is all zeros. If an instruction does not affect the FLAGS
register, then the state of the FLAGS register is reset to 0 upon the execution.
Unused 12 bits V L G E
15 3 2 1 0
The only operation allowed in the FLAGS register is “mov reg1 FLAGS”, where reg1 can be
any of the registers from R0 to R6. This instruction reads FLAGS register and writes the data
into reg1. All other operations on the FLAGS register are prohibited.
The cmp instruction can implicitly write to the FLAGS register. Similarly, conditional jump
instructions can implicitly read the FLAGS register.
Example:
R0 has 5, R1 has 10
Implicit write: cmp R0 R1 will set the L (less than) flag in the FLAGS register.
Implicit read: jlt 10001001 will read the FLAGS register and figure out that the L flag was
set, and then jump to address 10001001.
Binary Encoding
The ISA has 6 types of instructions with distinct encoding styles. However, each instruction is of
16 bits, regardless of the type.
● Type F: halt
opcode unused
(5 bits) (11 bits)
15 10 0
Binary representation for the register are given as follows:-
Register Address
R0 000
R1 001
R2 010
R3 011
R4 100
R5 101
R6 110
FLAGS 111
code
variables
Questions:
Q1: Assembler:
Program an assembler for the aforementioned ISA and assembly. The input to the assembler is
a text file containing the assembly instructions. Each line of the text file may be of one of 3
types:
● Empty line: Ignore these lines
● A label followed by an instruction
● An instruction
● A variable definition
If the code is error free, then the corresponding binary is generated. The binary file is a
text file in which each line is a 16bit binary number written using 0s and 1s in ASCII. The
assembler can write less than or equal to 256 lines.
Input/Output format:
● The assembler must read the assembly program as an input text file (stdin).
● The assembler must generate the binary (if there are no errors) as an output text file
(stdout).
● The assembler must generate the error notifications along with line number on which the
error was encountered (if there are errors) as the output text file (stdout). In case of
multiple errors, the assembler may print any one of the errors.
white(not halted)
{
Instruction = MEM.getData(PC); // Get current instruction
halted, new_PC = EE.execute(Instruction); // Update RF compute new_PC
PC.dump(); // Print PC
RF.dump(); // Print RF state
PC.update(new_PC); // Update PC
}
MEM.dump() // Print memory state