Lab 4: Arithmetic Logic Unit (ALU)

Similar documents
Lab 5: Arithmetic Logic Unit (ALU)

ECEN 468 Advanced Logic Design

Chap 6 - Introduction to HDL (b)

Basic operators, Arithmetic, Relational, Bitwise, Logical, Assignment, Conditional operators. JAVA Standard Edition

Course Topics - Outline

Introduction to Digital VLSI Design מבוא לתכנון VLSI ספרתי

ECE 4514 Digital Design II. Spring Lecture 7: Dataflow Modeling

Arithmetic Operators There are two types of operators: binary and unary Binary operators:

GO - OPERATORS. This tutorial will explain the arithmetic, relational, logical, bitwise, assignment and other operators one by one.

ECE Digital System Design & Synthesis Exercise 1 - Logic Values, Data Types & Operators - With Answers

JAVA OPERATORS GENERAL

Java provides a rich set of operators to manipulate variables. We can divide all the Java operators into the following groups:

Verilog Dataflow Modeling

Chapter 3: Dataflow Modeling

EE 231 Fall EE 231 Lab 3. Decoders and Multiplexers. Figure 1: 7-Segment Display. Memory: where the program is stored.

9/10/10. Arithmetic Operators. Today. Assigning floats to ints. Arithmetic Operators & Expressions. What do you think is the output?

Lecture #2: Verilog HDL

5 Arithmetic Logic Unit

EE 231 Fall Lab 2: Decoders and Multiplexers. Introduction

Introduction. Following are the types of operators: Unary requires a single operand Binary requires two operands Ternary requires three operands

14:332:231 DIGITAL LOGIC DESIGN. Hardware Description Languages

A Verilog Primer. An Overview of Verilog for Digital Design and Simulation

IT T35 Digital system desigm y - ii /s - iii

Operators in C. Staff Incharge: S.Sasirekha

EE 231 Fall EE 231 Lab 3

Combinational Verilog Intro. EECS 270 Labs

Lecture 3: Modeling in VHDL. EE 3610 Digital Systems

Prof. Navrati Saxena TA: Rochak Sachan

Operators. Java operators are classified into three categories:

EE 3170 Microcontroller Applications

Brief Introduction to Verilog HDL (Part 1)

SECTION II: LANGUAGE BASICS

RUBY OPERATORS. Ruby Arithmetic Operators: Ruby Comparison Operators:

MC9S12 Address Space

Lab 8 (Sections 300, 301 and 302) Prelab: ALU and ALU Control

CT 229. Java Syntax 26/09/2006 CT229

Verilog HDL Introduction

Department of Computer Science

Operators & Expressions

Verilog. Reminder: Lab #1 due tonight! Fall 2008 Lecture 3

Unit-2 (Operators) ANAND KR.SRIVASTAVA

Introduction to the 9S12 Microcontroller

Module 2 - Part 2 DATA TYPES AND EXPRESSIONS 1/15/19 CSE 1321 MODULE 2 1

Lab 1: Introduction to Verilog HDL and the Xilinx ISE

Verilog introduction. Embedded and Ambient Systems Lab

The Arithmetic Operators. Unary Operators. Relational Operators. Examples of use of ++ and

The Arithmetic Operators

Unit 3. Operators. School of Science and Technology INTRODUCTION

Digital Design (VIMIAA01) Introduction to the Verilog HDL

EE 3170 Microcontroller Applications

A flow chart is a graphical or symbolic representation of a process.

Verilog Design Principles

Character Set. The character set of C represents alphabet, digit or any symbol used to represent information. Digits 0, 1, 2, 3, 9

Chapter 3: Operators, Expressions and Type Conversion

Design Using Verilog

Arithmetic Operations

Why Should I Learn This Language? VLSI HDL. Verilog-2

BUILDING BLOCKS OF A BASIC MICROPROCESSOR. Part 1 PowerPoint Format of Lecture 3 of Book

In this lecture, we will go beyond the basic Verilog syntax and examine how flipflops and other clocked circuits are specified.

Informatics Ingeniería en Electrónica y Automática Industrial

a, b sum module add32 sum vector bus sum[31:0] sum[0] sum[31]. sum[7:0] sum sum overflow module add32_carry assign

Java provides a rich set of operators to manipulate variables. We can divide all the Java operators into the following g roups:

Arithmetic Operators. Portability: Printing Numbers

Logic Design: Part 2

Objectives. After completing this module, you will be able to:

EE 231 Fall Lab 1: Introduction to Verilog HDL and Altera IDE

VERILOG 2: LANGUAGE BASICS

Expressions and Precedence. Last updated 12/10/18

EKT 422/4 COMPUTER ARCHITECTURE. MINI PROJECT : Design of an Arithmetic Logic Unit

Arithmetic and Logical Operations

Information Science 1

Introduction To Verilog Design. Chun-Hung Chou

Digital Design with FPGAs. By Neeraj Kulkarni

Introduction to Embedded Microcomputer Systems Lecture 6.1

Arithmetic and Logic Blocks

Operators in java Operator operands.

bitwise inclusive OR Logical logical AND && logical OR Ternary ternary? : Assignment assignment = += -= *= /= %= &= ^= = <<= >>= >>>=

Java provides a rich set of operators to manipulate variables. We can divide all the Java operators into the following groups:

Will introduce various operators supported by C language Identify supported operations Present some of terms characterizing operators

Spiral 1 / Unit 4 Verilog HDL. Digital Circuit Design Steps. Digital Circuit Design OVERVIEW. Mark Redekopp. Description. Verification.

Digital Design with SystemVerilog

This Lecture. Some components (useful for the homework) Verilog HDL (will continue next lecture)

Department of Computer Science and Electrical Engineering. Intro to Verilog II

C expressions. (Reek, Ch. 5) 1 CS 3090: Safety Critical Programming in C

Binary Arithmetic CS 64: Computer Organization and Design Logic Lecture #2 Fall 2018

COMP Primitive and Class Types. Yi Hong May 14, 2015

ME 461 C review Session Fall 2009 S. Keres

Le L c e t c ur u e e 2 To T p o i p c i s c t o o b e b e co c v o e v r e ed e Variables Operators

EXPERIMENT NUMBER 11 REGISTERED ALU DESIGN

Lecture Topics. Announcements. Today: Integer Arithmetic (P&H ) Next: continued. Consulting hours. Introduction to Sim. Milestone #1 (due 1/26)

ESCI 386 IDL Programming for Advanced Earth Science Applications Lesson 1 IDL Operators

Lecture 3 Tao Wang 1

CSE140L: Components and Design Techniques for Digital Systems Lab. Verilog HDL. Instructor: Mohsen Imani UC San Diego. Source: Eric Crabill, Xilinx

A complex expression to evaluate we need to reduce it to a series of simple expressions. E.g * 7 =>2+ 35 => 37. E.g.

Lecture 7 Assembly Programming: Shift & Logical

Shift and Rotate Instructions

Introduction to Computers - Chapter 4

COMP 122/L Lecture 2. Kyle Dewey

Chapter 4 Arithmetic Functions

Project Gummi. 16-bit Microprocessor

Transcription:

EE 231-1 - Fall 2016 Lab 4: Arithmetic Logic Unit (ALU) Introduction 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 use the Verilog language to implement an ALU having 10 functions. Use of the case structure will make this job easy. ACCA Data_Out Alu_Ctrl ALU Z C Result Figure 1: Arithmetic Logic Unit (ALU) 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. Do NOT 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 Ctrl as the selection lines. 1 Prelab 1.1. Fill out Table 1 (Give unique values to each instruction.) How many bits should Alu Ctrl be? 1.2. Write code to implement the ALU. 2 Lab 2.1. Write a Verilog program based off of your code written in the Prelab to implement the ALU. 2.2. Design the ALU using Verilog. Make sure you deal with any unused bit combinations of the Alu Ctrl lines. (Hint: review default cases)

EE 231-2 - Fall 2016 2.3. Simulate the ALU and test different combinations of DATA and ACCA. Test ALL of the instructions. 2.4. Create another program that will call your ALU module. In this module, have ACCA and DATA as external inputs as well as Alu Ctrl. Output your results on two 7-segment displays. (Pinouts are included in Table 2) 2.5. Program your ALU code into your FPGA. Table 1: Arithmetic Logic Unit Instructions Alu Ctrl Instruction Operation (Mnemonic) LDDA Loads ACCA with the value on the Data bus. Z changes to 1 if Result == 0. (Load ACCA from Data) ADDA Adds the value on the Data bus to the value in ACCA and saves the result in ACCA. C is the carry (out) from addition and Z is set if the result is 0. (Add ACCA and Data) SUBA Subtracts the value on the Data bus from the value in ACCA and saves the result in ACCA. C is the carry (in) from subtraction and Z is set if the result is 0. (Subtract value in Data from ACCA) ANDA Perform a bitwise AND of the value on the Data bus with the value in ACCA. Save the result in ACCA. C should be the logical AND of the value on the Data bus with the value in ACCA. Z is set if the result is 0. (AND of ACCA and value on Data) ORAA Perform a bitwise OR of the value on the Data bus with the value in ACCA. Save the result in ACCA. C should be the logical OR of the value on the Data bus with the value in ACCA. Z is set if the result is 0. (OR of ACCA and value on Data) COMA Replace the value in ACCA with its one s complement. C is set to 1 and Z is set if the result is 0. (Compliment ACCA) INCA Increment value in ACCA. Z is set if the result is 0. (INCA ACCA) LSLA Logical shift left of ACCA. C is set to the previous MSB of ACCA and Z is set if the result is 0. (Logical shift left ACCA) LSRA Logical shift right of ACCA. C is set to the previous LSB of ACCA and Z is set if the result is 0. (Logical shift right ACCA) ASRA Arithmetic shift right of ACCA. C is set to the previous LSB of ACCA and Z is set if the result is 0. (Arithmetic shift right ACCA) ZERO Zero the value of ACCA. C is set to 0 and Z is set to 1. (Zero ACCA) RST Reset ACCA to 0xFF. C is set to 0 and Z is set to 0. (Reset ACCA)

EE 231-3 - Fall 2016 Table 2: CMOD-S6 DIP Assignments DIP Pin FPGA Pin Wire Wire FPGA Pin DIP Pin 1 P5 PIO01 PIO48 M2 48 2 N5 PIO02 PIO47 M1 47 3 N6 PIO03 PIO46 L2 46 4 P7 PIO04 PIO45 L1 45 5 P12 PIO05 PIO44 K2 44 6 N12 PIO06 PIO43 K1 43 7 L14 PIO07 PIO42 J2 42 8 L13 PIO08 PIO41 J1 41 9 K14 PIO09 PIO40 G2 40 10 K13 PIO10 PIO39 G1 39 11 J14 PIO11 PIO38 H2 38 12 J13 PIO12 PIO37 H1 37 13 H14 PIO13 PIO36 F2 36 14 H13 PIO14 PIO35 F1 35 15 F14 PIO15 PIO34 E2 34 16 F13 PIO16 PIO33 E1 33 17 G14 PIO17 PIO32 D2 32 18 G13 PIO18 PIO31 D1 31 19 E14 PIO19 PIO30 C1 30 20 E13 PIO20 PIO29 B1 29 21 D14 PIO21 PIO28 A2 28 22 D13 PIO22 PIO27 B3 27 23 C13 PIO23 PIO26 A3 26 24 VU GND 25 3 Supplement: Verilog (3) 3.1 Parameterization 3.1.1 Macros Listing 1: Macros in Verilog 1 define Rst_Addr 8 hff // Gets Expaned 2 assign data = Rst_Addr; // Tic is Necessary 3.1.2 Parameters Listing 2: Parameters in Verilog

EE 231-4 - Fall 2016 1 parameter num = 8; Parameters are constants, not variables. 3.2 Operators 3.2.1 Ternary Operator 1 assign y = sel? a : b; Listing 3: Ternary Operator in Verilog If sel is true, y is assigned to a, otherwise it is assigned to b. 3.2.2 Concatenation 1 {a, b, c} Listing 4: Concatenation in Verilog Bits are concatenated using { }. 3.2.3 Comparison 1 if(a > b) y = a; Listing 5: Comparison in Verilog Compare a to b, if true set y equal to a. Other comparisons are listed in Listing 6. 1 > // Greater than 2 < // Less than 3 >= // Greater than or equal to 4 <= // Less than or equal to 5 == // Equality 6 === // Equality including X and Z 7!= // Inequality 8!== // Inequality including X and Z Listing 6: Comparison Operators 3.2.4 Logical Operators 1! // Logical negation 2 && // Logical and 3 // Logical or Listing 7: Logical Operators

EE 231-5 - Fall 2016 3.2.5 Binary Arithmetic Operators 1 + // Addition 2 - // Subtraction 3 * // Multiplication 4 / // Division (truncated) 5 % // Modulus Listing 8: Binary Arithmetic Operators 3.2.6 Unary Arithmetic Operators Listing 9: Unary Arithmetic Operators 1 - // Change the sign of the operand 3.2.7 Bitwise Operators 1 ~ // Bitwise negation 2 & // Bitwise AND 3 // Bitwise OR 4 ^ // Bitwise XOR 5 ~^ // Bitwise XNOR 6 ^~ // Bitwise XNOR (also) Listing 10: Bitwise Operators 3.2.8 Unary Reduction Operators Produce a single bit result by applying the operator to all the bits of the operand. 1 ~ // Bitwise negation 2 & // Bitwise AND 3 // Bitwise OR 4 & // Reduction NAND 5 ~ // Reduction NOR 6 ^ // Bitwise XOR 7 ~^ // Bitwise XNOR 8 ^~ // Bitwise XNOR (also) Listing 11: Unary Reduction Operators 3.2.9 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. 1 << // Logical left shift 2 >> // Logical right shift Listing 12: Shift Operators

EE 231-6 - Fall 2016 3.2.10 Precedence 1 /* Highest Precedence */ 2!, ~ 3 *, /, % 4 +, - 5 <<, >> 6 <, <=, >, >= 7 & 8 ^, ^~ 9 10 && 11 12?: 13 /* Lowest Precedence */ Listing 13: Precedence