Docsity

Lab 5: Implementing an Arithmetic Logic Unit (ALU) using Verilog - Prof. Aly El Osery, Lab Reports of Digital Electronics

Toggle sidebar
bg1
Lab 5: Arithmetic Logic Unit (ALU)
October 10, 2008
Contents
1 Prelab 4
2 Lab 4
3 Supplementary Material 6
3.1 Verilog................................. 6
3.1.1 Parameters . . . . . . . . . . . . . . . . . . . . . . . . . . 6
3.1.2 Operators . . . . . . . . . . . . . . . . . . . . . . . . . . . 6
3.1.3 8-bit Adder . . . . . . . . . . . . . . . . . . . . . . . . . . 8
The heart of every computer is an Arithmetic Logic Unit (ALU). This is
the part of the computer which performs arithmetic operations on numbers,
e.g. addition, subtraction, etc. In this lab you will use the Verilog language to
implement an ALU having 10 functions. Use of the case structure will make
this job easy.
ALU
[? : 0] ALU CTL
C
Z
[7 : 0] ACCA
[7 : 0] DATA
[7 : 0] result
Figure 1: ALU block diagram
1
pf3
pf4
pf5
pf8
pf9

Partial preview of the text

Download Lab 5: Implementing an Arithmetic Logic Unit (ALU) using Verilog - Prof. Aly El Osery and more Lab Reports Digital Electronics in PDF only on Docsity!

Lab 5: Arithmetic Logic Unit (ALU)

October 10, 2008

Contents

1 Prelab 4

2 Lab 4

3 Supplementary Material 6 3.1 Verilog................................. 6 3.1.1 Parameters.......................... 6 3.1.2 Operators........................... 6 3.1.3 8-bit Adder.......................... 8

The heart of every computer is an Arithmetic Logic Unit (ALU). This is the part of the computer which performs arithmetic operations on numbers, e.g. addition, subtraction, etc. In this lab you will use the Verilog language to implement an ALU having 10 functions. Use of the case structure will make this job easy.

ALU

[? : 0] ALU CTL

C

Z

[7 : 0] ACCA

[7 : 0] DATA

[7 : 0] result

Figure 1: ALU block diagram

The ALU that you will build (see Figure 1) will perform 10 functions on 8-bit inputs (see Table 1). Please make sure you use the same variable name as the ones used in this lab. Don’t make your own. The ALU will generate an 8-bit result (result), a one bit carry (C), and a one bit zero-bit (Z). To select which of the 10 functions to implement you will use ALU CTL as the selection lines.

Table 1: ALU Functions

ALU CTL Mnemonic Description

Load

(load DATA into result) DATA => result C is a don’t care 1 → Z if result == 0, 0 → Z otherwise

ADDA

(add DATA to ACCA) ACCA + DATA => result C is carry from addition 1 → Z if result == 0, 0 → Z otherwise

SUBA

(subtract DATA from ACCA) ACCA − DATA => result C is borrow from subtraction 1 → Z if result == 0, 0 → Z otherwise

ANDA

(logical AND DATA with ACCA) ACCA&DATA => result C is a don’t care 1 → Z if result == 0, 0 → Z otherwise

ORAA

(logical OR DATA with ACCA) ACCA|DATA => result C is a don’t care 1 → Z if result == 0, 0 → Z otherwise

COMA

(complement of ACCA) ACCA => result 1 => C 1 → Z if result == 0, 0 → Z otherwise

INCA

(increment ACCA by 1) ACCA + 1 => result C is a don’t care 1 → Z if result == 0, 0 → Z otherwise

LSRA

(logical shift right of ACCA) Shift all bits of ACCA one place to the right: 0 => results[7], ACCA[7 : 1] → result[6 : 0] ACCA[ 0 ] => C 1 → Z if result == 0, 0 → Z otherwise

LSLA

(logical shift left of ACCA) Shift all bits of ACCA one place to the left:

1 Prelab

  1. Fill out Table 1.
  2. Write a Verilog program to implement the ALU.

2 Lab

  1. Design the ALU using Verilog. (Make sure you deal with any unused bit combinations of the ALU CTL lines).
  2. Simulate the ALU and test different combinations of DATA and ACCA.
  3. Program your ALU code into your CPLD.
  4. Create another program that will call your ALU module. In this module read external inputs for ACCA and DATA as well as the ALU CTR. Output your results on two 7-segment displays (Pinout of the MAX II micro board is shown in Figure 2).

Figure 2: I/O map of prototyping areas

Table 3: Logical Operators Operator Description ! logical negation && logical AND || logical OR

Logical Operators Table 3 shows a list of logical operators.

  • Evaluation is performed left to right.
  • x if any of the operands has unknown x bits.

Binary Arithmetic Operators Table 4 shows a list of arithmetic operators.

Table 4: Arithmetic Operators Operator Description

  • addition − subtraction ∗ multiplication / division (truncates any fractional part) % equality

Unary Arithmetic Operators Table 5 shows a list of unary arithmetic operators.

Table 5: Unary Arithmetic Operators Operator Description − Change the sign of the operand

Bitwise Operators Table 6 shows a list of bitwise operators.

Unary Reduction Operators Table 7 shows a list of unary reduction op- erators. They produce a single bit result by applying the operator to all of the pits of the operand.

Shift Operators Table 8 shows a list of shift operators.

  • Left operand is shifted by the number of bit positions given by the right operand.
  • Zeros are used to fill vacated bit positions.

Table 6: Bitwise Operators Operator Description ∼ Bitwise negation & Bitwise AND | Bitwise OR ∼ & Bitwise NAND ∼ | Bitwise OR ∼∧^ or ∧^ ∼ Equivalence

Table 7: Unary Reduction Operators Operator Description ∼ Bitwise negation & Bitwise AND | Bitwise OR ∼ & Bitwise NAND ∼ | Bitwise OR ∼∧^ or ∧^ ∼ Equivalence

Operator Precedence Rule Table 9 shows a list operator precedence rules.

3.1.3 8-bit Adder

Program 1 shows how to implement an 8-bit adder.

Program 1 An example of an 8-bit adder.

wire [7:0] sum, a, b; wire cin,cout;

assign {cout,sum} = a+b+cin;