Design And Implement A Circuit In HDL Assignment

Assignment Task

Description

In-course assessment. Requires design implementation and testing of code written in HDL and assembly language

Rationale

Provides an opportunity to write HDL and assembly code including understanding the implementation of branching and functions.

Learning outcomes assessed

The basic building blocks of a computer in detail and explain how they are composed to construct computing machinery.

Apply appropriate tools to develop, simulate and test logic circuits (CAD).

Explain how high level programming constructs, such as ’if’ statements and ’for’ loops, are implemented at a machine level

Assignment guidance

1. There are two sections to this resit assessment. Section I requires the implementation of HDL programs and Section II requires the implementation of assembly language.

2. Assessment tasks

Section I

Your task is to design and implement a circuit in hdl which takes two 2-bit numbers (A, B) and (C, D) as input and produces a 3-bit output (E, F, G).

The final circuit has 6 inputs in total (f1, f0, A, B, C, D) and 3 outputs (E, F, G). The function of the circuit is determined by the two inputs f1 and f0.

The truth tables below define the operation of the circuit for each combination of f1 and f0.

Table 1: When f1 , f 0 = (1, 1) FZero

ABCDFG
000011
000110
001001
001100
010011
010110
011001
011100
100011
100110
101001
101100
110011
110110
111001
111100

Table 2: When (f 1, f 0) = (1, 0) FOne

ABCDFG
000000
000100
001000
001100
010000
010101
011000
011101
100000
100100
101010
101110
110000
110101
111010
111111

 

Table3:When (f1,f0)=(0,1)FTwo 

ABCDFG
000000
000101
001010
001111
010001
010101
011011
011111
100010
100111
101010
101111
110011
110111
111011
111111

Table4:When (f1,f0)=(0,0 )FThree

ABCDEFG
0000000
0001001
0010010
0011011
0100001
0101010
0110011
0111100
1000010
1001011
1010100
1011101
1100011
1101100
1110101
1111110

Table 4:When (f1,f0)=(0,0 )FThree

a) For each of the truth tables above, implement a logic circuit in HDL that will perform the function specified by the truth table. You should create one circuit for each truth table and test it produces the required output for that truth table. The circuit for each truth table should be named FZero, FOne, FTwo, FThree corresponding to the names of the truth tables given above and must have corresponding filenames FZero.hdl, FOne.hdl, FTwo.hdl, FThree.hdl.

Each circuit must have four inputs named A, B, C and D. Chips FZero, FOne and FTwo will have two outputs (F,G). Chip FThree will have three outputs named E,F and G.

You must only use the built-in AND, NAND, OR, NOR, NOT, Mux, XOR or DMux chips.

The test files provided (.tst and .cmp) can be used to test each output of a chip. For example FZero1.tst tests the F output of the chip FZero.hdl and FZero2.tst tests the G output of FZero.hdl.

b) Combine all four circuits into one circuit which takes all six inputs and three outputs and test it to ensure it produces the correct output depending on the value of the inputs f1 and f0. Call the chip FALL. You can test this chip using FALL.tst but may wish to create further tests before submission. The value of output is undefined (can be either 0 or 1) unless (f1, f0) = (0, 0)

You must only use the built-in AND, NAND, OR, NOR, NOT, Mux, XOR or DMux chips.

c) Stretch Activity When performing computational operations it is often useful to be able to exe- cute a sequence of operations, each one using the output of the previous step as an input to the next step. For example to OR 3 values X OR Y OR Z you might first calculate X ORY and then on the next step apply ORZ to the previous output (X OR Y ).

For this task adapt the circuit FALL so that it can combine a sequence of operations defined by different values for f1 and f0 at each step, by enabling the outputs Ft and Gt of step t to be used (feedback) as the inputs for the next

operation Ct+1 and Dt+1 for step t + 1. You should also add a further input (Load) to the chip which when Load = 1 will enable you to load new inputs to

Ct and Dt and when set to 0 sets Ct+1 = Ft and Dt+1 = Gt. The Load input will allow you to manually set the values of C and D at the start and during the sequence if required.

Call this chip FSEQ. You can test this chip using FSEQ.tst but may wish to create further tests before submission. You must only use the built-in AND, NAND, OR, NOR, NOT, Mux, DMux,

XOR or DFF chips.

Section II

The Feistel cipher is a symmetric block cipher encryption framework which is the basis of many modern day encryption algorithms. In this coursework you will implement a Feistel cipher system as a software implementation in both a high level language and Hack Assembly.

In a Feistel cipher the plaintext, P, to be encrypted is split into two equal size parts

L0 and R0 such that P = L0R0. A function F is applied to one half of the plaintext, combined with a key, and the result is XOR’d with the other half of the plaintext.

Feistel ciphers often employ multiple rounds of this scheme. In general the scheme works as follows, for all i = 0, . . . n,

Li+1 =Ri

Ri+1 = Li ⊕F (Ri, Ki)

To decrypt an encrypted message using this cipher we can apply the same procedure in reverse. For i = n, n   − 1 , . . . , 0 ,

Ri    Li+1

L=    Ri+1         ⊕F( Li+1 , Ki)

For this coursework, we are interested in the 16-bit Feistel cipher which uses 4 rounds.

The function F(A, B) = A

⊕¬B.

The keys are derived from a single 8-bit key K0 such that,

K0 = b7b6b5b4b3b2b1b0

K1 = b6b5b4b3b2b1b0b7

K2 = b5b4b3b2b1b0b7b6

K3 = b4b3b2b1b0b7b6b5

a) Write a program (XOR.asm) in HACK assembly that implements an XOR function between two 16-bit values stored in RAM[3] and RAM[4] and stores the result in RAM[5].

b) Write a program (Rotate.asm) in HACK assembly that implements an algorithm to rotate the bits of a 16-bit number left (Least Significant bit (LSb) to Most Significant bit (MSb)). The original number should be stored in RAM[3] the number of times to rotate the bits should be in RAM[4] and the result stored in

RAM[5], i.e. 1010111100000000 rotated left 3 times would be 0111100000000101

where the MSb is used to replace the LSb.

c) Write a program (FeistelEncryption.asm) in HACK assembly, that implements the described Feistel encryption system. The initial key, K0, will be stored in RAM[1], and the 16-bit plaintext will be stored in RAM[2]. The result of the encryption should be stored in RAM[0].