Arithmetic Operations

Similar documents
Arithmetic and Logical Operations

BINARY SYSTEM. Binary system is used in digital systems because it is:

Chapter 4. Operations on Data

The ALU consists of combinational logic. Processes all data in the CPU. ALL von Neuman machines have an ALU loop.

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

Chapter 10 Binary Arithmetics

Binary Addition. Add the binary numbers and and show the equivalent decimal addition.

But first, encode deck of cards. Integer Representation. Two possible representations. Two better representations WELLESLEY CS 240 9/8/15

Chapter 4 Arithmetic Functions

CHAPTER V NUMBER SYSTEMS AND ARITHMETIC

Register Transfer Language and Microoperations (Part 2)

4 Operations On Data 4.1. Foundations of Computer Science Cengage Learning

Semester Transition Point. EE 109 Unit 11 Binary Arithmetic. Binary Arithmetic ARITHMETIC

2.1. Unit 2. Integer Operations (Arithmetic, Overflow, Bitwise Logic, Shifting)

Chapter 3: part 3 Binary Subtraction

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

COE 202: Digital Logic Design Number Systems Part 2. Dr. Ahmad Almulhem ahmadsm AT kfupm Phone: Office:

Integer Representation

CS 64 Week 1 Lecture 1. Kyle Dewey

4 Operations On Data 4.1. Foundations of Computer Science Cengage Learning

EE 109 Unit 6 Binary Arithmetic

Module 2: Computer Arithmetic

Integers II. CSE 351 Autumn Instructor: Justin Hsia

Operations On Data CHAPTER 4. (Solutions to Odd-Numbered Problems) Review Questions

CHW 261: Logic Design

ENE 334 Microprocessors

LAB A Translating Data to Binary

CHAPTER 6 ARITHMETIC, LOGIC INSTRUCTIONS, AND PROGRAMS

ECEN 468 Advanced Logic Design

Chapter 5: Computer Arithmetic. In this chapter you will learn about:

Beginning C Programming for Engineers

Learning Objectives. Binary over Decimal. In this chapter you will learn about:

COMP2611: Computer Organization. Data Representation

Integers II. CSE 351 Autumn Instructor: Justin Hsia

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

Number System. Introduction. Decimal Numbers

INF2270 Spring Philipp Häfliger. Lecture 4: Signed Binaries and Arithmetic

Number Systems and Computer Arithmetic

Number Systems and Conversions UNIT 1 NUMBER SYSTEMS & CONVERSIONS. Number Systems (2/2) Number Systems (1/2) Iris Hui-Ru Jiang Spring 2010

Computer Architecture and Organization: L04: Micro-operations

CS 253. January 14, 2017

Integers II. CSE 351 Autumn 2018

Chapter 3: Arithmetic for Computers

Data Representation. DRAM uses a single capacitor to store and a transistor to select. SRAM typically uses 6 transistors.

Number representations

Goals for this Week. CSC 2400: Computer Systems. Bits, Bytes and Data Types. Binary number system. Finite representations of binary integers

9 Multiplication and Division

CS33 Project Gear Up. Data

COMP 122/L Lecture 2. Kyle Dewey

Digital Arithmetic. Digital Arithmetic: Operations and Circuits Dr. Farahmand

Lecture 8: Addition, Multiplication & Division

Lecture 12 Integers. Computer and Network Security 19th of December Computer Science and Engineering Department

Chapter 5: Computer Arithmetic

COMP 303 Computer Architecture Lecture 6

Groups of two-state devices are used to represent data in a computer. In general, we say the states are either: high/low, on/off, 1/0,...

SIGNED AND UNSIGNED SYSTEMS

World Inside a Computer is Binary

ECE 2030B 1:00pm Computer Engineering Spring problems, 5 pages Exam Two 10 March 2010

Week 7: Assignment Solutions

CS/COE 0447 Example Problems for Exam 2 Spring 2011

Bitwise Instructions

Number Systems CHAPTER Positional Number Systems

BITWISE OPERATORS. There are a number of ways to manipulate binary values. Just as you can with

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

Organisasi Sistem Komputer

Kinds Of Data CHAPTER 3 DATA REPRESENTATION. Numbers Are Different! Positional Number Systems. Text. Numbers. Other

CS 31: Intro to Systems Binary Arithmetic. Kevin Webb Swarthmore College January 26, 2016

NUMBER SCALING FOR THE LGP-27

Bits, Words, and Integers

DLD VIDYA SAGAR P. potharajuvidyasagar.wordpress.com. Vignana Bharathi Institute of Technology UNIT 1 DLD P VIDYA SAGAR

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

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

Arithmetic and Bitwise Operations on Binary Data

Two-Level CLA for 4-bit Adder. Two-Level CLA for 4-bit Adder. Two-Level CLA for 16-bit Adder. A Closer Look at CLA Delay

Integer Encoding and Manipulation

Number Systems. Both numbers are positive

carry in carry 1101 carry carry

A complement number system is used to represent positive and negative integers. A complement number system is based on a fixed length representation

CPE300: Digital System Architecture and Design

Binary Adders. Ripple-Carry Adder

JAVA OPERATORS GENERAL

UNIT-III REGISTER TRANSFER LANGUAGE AND DESIGN OF CONTROL UNIT

Lecture Topics. Announcements. Today: Integer Arithmetic (P&H ) Next: The MIPS ISA (P&H ) Consulting hours. Milestone #1 (due 1/26)

1010 2?= ?= CS 64 Lecture 2 Data Representation. Decimal Numbers: Base 10. Reading: FLD Digits: 0, 1, 2, 3, 4, 5, 6, 7, 8, 9

CS 31: Introduction to Computer Systems. 03: Binary Arithmetic January 29

CS/COE0447: Computer Organization

CS/COE0447: Computer Organization

ECE 30 Introduction to Computer Engineering

Binary Adders: Half Adders and Full Adders

ECE 375: Computer Organization and Assembly Language Programming

EEM336 Microprocessors I. Arithmetic and Logic Instructions

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

Combinational and sequential circuits (learned in Chapters 1 and 2) can be used to create simple digital systems.

MC1601 Computer Organization

Data Representation COE 301. Computer Organization Prof. Muhamed Mudawar

Addition and multiplication

Floating-Point Data Representation and Manipulation 198:231 Introduction to Computer Organization Lecture 3

Arithmetic and Bitwise Operations on Binary Data

CHAPTER 4: Register Transfer Language and Microoperations

EE260: Logic Design, Spring n Integer multiplication. n Booth s algorithm. n Integer division. n Restoring, non-restoring

Transcription:

Arithmetic Operations Arithmetic Operations addition subtraction multiplication division Each of these operations on the integer representations: unsigned two's complement 1

Addition One bit of binary addition carry out + a b carry in sum bit 2

Addition Truth Table 3 Carry In a b Carry Out Sum Bit 0 0 0 0 0 0 0 1 0 1 0 1 0 0 1 0 1 1 1 0 1 0 0 0 1 1 0 1 1 0 1 1 0 1 0 1 1 1 1 1

Addition Unsigned and 2's complement use the same addition algorithm Due to the fixed precision, throw away the carry out from the msb 00010111 + 10010010 4

Two s Complement Addition 1 1 1 1 1 1 1 0 ( ) + 0 0 0 0 0 0 0 1 ( ) ( ) 1 1 1 1 0 0 0 0 ( ) + 0 0 1 1 0 0 0 0 ( ) ( ) 5

Overflow The condition in which the result of an arithmetic operation cannot fit into the fixed number of bits available. For example: +8 cannot fit into a 3-bit, unsigned representation. It needs 4 bits: 1000 6

Overflow Detection Most architectures have hardware that detects when overflow has occurred (for arithmetic operations). The detection algorithms are simple. 7

6-bit examples: Unsigned Overflow Detection 0 0 1 1 1 1 1 1 1 1 1 1 + 0 0 1 1 1 1 + 0 0 0 0 0 1 1 0 0 0 0 0 + 1 0 0 0 0 0 Carry out from msbs is overflow in unsigned 8

Unsigned Overflow Detection 6-bit examples: 0 0 1 1 1 1 1 1 1 1 1 1 + 0 0 1 1 1 1 + 0 0 0 0 0 1 0 1 1 1 1 0 0 0 0 0 0 0 0 1 No Overflow Overflow! 1 1 0 0 0 0 0 + 1 0 0 0 0 0 0 0 0 0 0 0 Overflow! 9 Carry out from msbs is overflow in unsigned

Two s Complement Overflow Detection When adding 2 numbers of like sign + to + - to and the sign of the result is different! + - + + + - - + Overflow! Overflow! 10

Addition Overflow detection: 2 s complement 6-bit examples 111111 + 111111 ( ) 100000 ( ) ( ) + 011111 ( ) ( ) ( ) 11 011111 + 011111 ( ) ( ) ( )

Subtraction basic algorithm is like decimal 0 0 = 0 1 0 = 1 1 1 = 0 0 1 =? BORROW! 111000-010110 12

Subtraction For two s complement representation The implementation redefines the operation: a b becomes a + (-b) This is a 2-step algorithm: 1. take the two s complement of b (common phrasing for: find the additive inverse of b) 2. do addition 13

Subtraction 6-bit, 2 s complement examples 001111-111100 ( ) ( ) 000010-011100 ( ) ( ) 14

Subtraction Overflow detection: 2 s complement If the addition causes overflow, so does the subtraction! 100000-000010 ( ) ( ) 15

Multiplication 0 0 = 0 0 1 = 0 1 0 = 0 1 1 = 1 Same algorithm as decimal There is a precision problem n bits * n bits n + n bits may be needed 16

In HW, space is always designated for a larger precision product. 32 bits * 32 bits 64 bits 17

Unsigned Multiplication 01111 * 01101 18

Unsigned Multiplication 11111 * 11111 19

Two s Complement Slightly trickier: must sign extend the partial products (sometimes!) 20

OR Sign extend multiplier and multiplicand to full width of product * product 21 And, use only exact number of lsbs of product

Multiplication + - + - + + - - OK sign ext. partial product reverse or additive inverses find additive inverses - + + + OK 22

Unsigned Division 11001 11 25/3 23

Sign Extension The operation that allows the same 2's complement value to be represented, but using more bits. 0 0 1 0 1 (5 bits) _ 0 0 1 0 1 (8 bits) 1 1 1 0 (4 bits) 1 1 1 0 (8 bits) 24

Zero Extension The same type of thing as sign extension, but used to represent the same unsigned value, but using more bits 0 0 1 0 1 (5 bits) _ 0 0 1 0 1 (8 bits) 1 1 1 1 (4 bits) 1 1 1 1 (8 bits) 25

Truth Table for a Few Logical Operations X Y X and Y X nand Y X or Y X xor Y 0 0 0 1 0 0 0 1 0 1 1 1 1 0 0 1 1 1 1 1 1 0 1 0 26

Logical Operations Logical operations are done bitwise on every computer Invented example: Assume that X,Y, and Z are 8-bit variables and Z, X, Y If X is 0 0 0 0 1 1 1 1 Y is 0 1 0 1 0 1 0 1 then Z is 27

To selectively clear bit(s) clear a bit means make it a 0 First, make a mask: (the generic description of a set of bits that do whatever you want them to) Within the mask, 1 s for unchanged bits 0 s for cleared bits To clear bits numbered 0,1, and 6 of variable X mask 1.. 1 0 1 1 1 1 0 0 and use the instruction and result, X, mask 28

To selectively set bit(s) set a bit means make it a 1 First, make a mask: 0 s for unchanged bits 1 s for set bits To set bits numbered 2,3, and 4 of variable X mask 0.. 0 0 0 1 1 1 0 0 and use the instruction or result, X, mask 29

Shift Moving bits around 1) arithmetic shift 2) logical shift 3) rotate Bits can move right or left 30

Arithmetic Shift Right sign extension! Left 31

Logical Shift Right Left Logical left is the same as arithmetic left. 32

Rotate Right Left 33 No bits lost, just moved

Assume a set of 4 chars. are in an integersized variable (X). Assume an instruction exists to print out the character all the way to the right putc X (prints D) Invent instructions, and write code to print ABCD, without changing X. 34

rotl X, 8 bits putc X # A rotl X, 8 bits putc X # B rotl X, 8 bits putc X # C rotl X, 8 bits putc X # D Karen s solution 35