The University of Adelaide, School of Computer Science

Slides:



Advertisements
Similar presentations
CS 151 Digital Systems Design Lecture 3 More Number Systems.
Advertisements

Assembly Language and Computer Architecture Using C++ and Java
Assembly Language and Computer Architecture Using C++ and Java
Lecture 5 Sept 14 Goals: Chapter 2 continued MIPS assembly language instruction formats translating c into MIPS - examples.
1 Binary Arithmetic, Subtraction The rules for binary arithmetic are: = 0, carry = = 1, carry = = 1, carry = = 0, carry =
Number Representation (1) Fall 2005 Lecture 12: Number Representation Integers and Computer Arithmetic.
ENGIN112 L3: More Number Systems September 8, 2003 ENGIN 112 Intro to Electrical and Computer Engineering Lecture 3 More Number Systems.
1 Binary Numbers Again Recall that N binary digits (N bits) can represent unsigned integers from 0 to 2 N bits = 0 to 15 8 bits = 0 to bits.
© 2010 Kettering University, All rights reserved..
Computer Organization & Programming Chapter2 Number Representation and Logic Operations.
Arithmetic for Computers
CSCI-365 Computer Organization Lecture Note: Some slides and/or pictures in the following are adapted from: Computer Organization and Design, Patterson.
Lecture 5.
#1 Lec # 2 Winter EECC341 - Shaaban Positional Number Systems A number system consists of an order set of symbols (digits) with relations.
Binary Arithmetic & Data representation
Lecture Objectives: 1)Define the terms least significant bit and most significant bit. 2)Explain how unsigned integer numbers are represented in memory.
BR 8/99 Binary Numbers Again Recall than N binary digits (N bits) can represent unsigned integers from 0 to 2 N bits = 0 to 15 8 bits = 0 to 255.
Positional Number Systems
Number Representation
ECE 2110: Introduction to Digital Systems Signed Addition/Subtraction.
Operations on Bits Arithmetic Operations Logic Operations
Microcomputers I - Electrical and Computer Engineering Dept. at Kettering.
Computer Math CPS120 Introduction to Computer Science Lecture 4.
Chapter 2 CSF 2009 The MIPS Assembly Language: Introduction to Binary System.
CPS3340 COMPUTER ARCHITECTURE Fall Semester, /08/2013 Lecture 10: MIPS Instructor: Ashraf Yaseen DEPARTMENT OF MATH & COMPUTER SCIENCE CENTRAL STATE.
Data Representation in Computer Systems. 2 Signed Integer Representation The conversions we have so far presented have involved only positive numbers.
07/12/ Data Representation Two’s Complement & Binary Arithmetic.
Irvine, Kip R. Assembly Language for Intel-Based Computers 6/e, Signed Integers The highest bit indicates the sign. 1 = negative, 0 = positive.
Digital Representations ME 4611 Binary Representation Only two states (0 and 1) Easy to implement electronically %0= (0) 10 %1= (1) 10 %10= (2) 10 %11=
1 Lecture 7: MARS, Computer Arithmetic Today’s topics:  MARS intro  Numerical representations  Addition and subtraction.
Chapter 2 — Instructions: Language of the Computer — 1 Memory Operands Main memory used for composite data – Arrays, structures, dynamic data To apply.
CHAPTER 3 Arithmetic For Computers 1/31/ Topics for discussion 1/31/ Number system: { radix/base, a set of distinct digits, operations} Radix.
DR. SIMING LIU SPRING 2016 COMPUTER SCIENCE AND ENGINEERING UNIVERSITY OF NEVADA, RENO Session 9 Binary Representation and Logical Operations.
May 2, 2001System Architecture I1 Systems Architecture I (CS ) Lecture 11: Arithmetic for Computers * Jeremy R. Johnson May 2, 2001 *This lecture.
Chapter 2 Instructions: Language of the Computer Part IIa Number Representation.
Nguyen Le CS147.  2.4 Signed Integer Representation  – Signed Magnitude  – Complement Systems  – Unsigned Versus Signed Numbers.
ECE 3110: Introduction to Digital Systems Signed Number Conversions and operations.
Lecture No. 4 Computer Logic Design. Negative Number Representation 3 Options –Sign-magnitude –One’s Complement –Two’s Complement  used in computers.
CS Computer Organization Numbers and Instructions Dr. Stephen P. Carl.
COMPUTER ARCHITECTURE & OPERATIONS I Instructor: Yaohang Li.
Computer Math CPS120 Introduction to Computer Science Lecture 7.
Lecture 4: Digital Systems & Binary Numbers (4)
1 CE 454 Computer Architecture Lecture 4 Ahmed Ezzat The Digital Logic, Ch-3.1.
Based on slides from D. Patterson and www-inst.eecs.berkeley.edu/~cs152/ COM 249 – Computer Organization and Assembly Language Chapter 3 Arithmetic For.
CS2100 Computer Organisation
Computer Architecture & Operations I
Addition and Subtraction
3.1 Denary, Binary and Hexadecimal Number Systems
Digital Systems and Number Systems
Data Representation Binary Numbers Binary Addition
Integer Real Numbers Character Boolean Memory Address CPU Data Types
Morgan Kaufmann Publishers
Data Representation in Computer Systems
Computer Architecture & Operations I
Lecture 2 Topics Binary Arithmetic (Unsigned binary operands)
The University of Adelaide, School of Computer Science
Addition and Substraction
The University of Adelaide, School of Computer Science
Data Representation in Computer Systems
Computer Architecture & Operations I
CS/COE0447 Computer Organization & Assembly Language
CS/COE0447 Computer Organization & Assembly Language
Binary “There are 10 types of people in the world: Those who understand binary, and those who don't.”
Computer Architecture
Decimal and binary representation systems
A 1-Bit Arithmetic Logic Unit
ECE 171 Digital Circuits Chapter 2 Binary Arithmetic
Copyright © Cengage Learning. All rights reserved.
COMS 361 Computer Organization
Presentation transcript:

The University of Adelaide, School of Computer Science 19 November 2018 Lecture 0 Number Representations & Operations Chapter 2 — Instructions: Language of the Computer

Objectives Understand that everything in digital word is stored and manipulated in binary format Master the skill to convert representations between various formats (e.g., binary format and hexadecimal format) Apply the conversion of unsigned and signed integer numbers between decimal format and binary format Perform the addition and subtraction between two numbers in hexadecimal format Detect the overflow of addition and subtraction between two numbers Chapter 2 — Instructions: Language of the Computer — 2

Coverage Textbook Chapter 2.4 Online sources Chapter 2 — Instructions: Language of the Computer — 3

Computer: a binary world Everything inside a computer is saved and manipulated at binary format, i.e., in the sequence of ones and zeros Chapter 2 — Instructions: Language of the Computer — 4

Hexadecimal format For the convenience of demonstration, binary format is typically displayed in hexadecimal format Each binary digit is called a bit A bit can be one of two possible values, i.e., 0 or 1 Eight consecutive bits are called a byte Byte is the default unit of capacity in computer world Each hexadecimal digit can be one of 16 possible values 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, A, B, C, D, E, F “0x” is the typical prefix to indicate hexadecimal format Chapter 2 — Instructions: Language of the Computer — 5

Conversion between binary and hexadecimal formats Convert 4 consecutive binary bits to 1 hexadecimal digit H B 8 1 9 2 A 3 4 C 5 D 6 E 7 F Chapter 2 — Instructions: Language of the Computer — 6

How to represent integers in a computer? The University of Adelaide, School of Computer Science 19 November 2018 How to represent integers in a computer? Covered in Chapter 2.4 Unsigned integer No sign, i.e., 0 or positive Signed integer Can be negative, 0, or positive No explicit ‘+’ or ‘-’ symbol to tell the sign of the number Two’s complement Incorporate the sign in the representation Sign extension Before we discuss the details of instruction set, we need to talk about two things. How are numbers are represented in a computer? How to store them and address them in the memory? Chapter 2 — Instructions: Language of the Computer — 7 Chapter 2 — Instructions: Language of the Computer

Generic numbering system N=cn-1…c3c2c1c0 N is an unsigned number represented by n digits What is the value of N? N=Cn-1…+C3+C2+C1+C0 The value of N is the sum of the values of all columns Ci=ci×qi q: is the base value i: is the column index Chapter 2 — Instructions: Language of the Computer — 8

Unsigned Binary Integers The University of Adelaide, School of Computer Science 19 November 2018 Unsigned Binary Integers Given an n-bit number §2.4 Signed and Unsigned Numbers Range: 0 to +2n – 1 Example 0000,0000,0000,0000,0000,0000,0000,10112 = 0 + … + 1×23 + 0×22 +1×21 +1×20 = 0 + … + 8 + 0 + 2 + 1 = 1110 Using 32 bits 0 to +4,294,967,295 The value of ith column is the value of the digit times its weight. The value of the n-bit number is the sum of the values of all columns. Chapter 2 — Instructions: Language of the Computer — 9 Chapter 2 — Instructions: Language of the Computer

Convert unsigned decimal integer to binary format Example: 87 87 = 64 + 16 + 4 + 2 + 1 = 26+24+22+21+20 8710 = 0101,01112 Chapter 2 — Instructions: Language of the Computer — 10

Two’s-Complement Signed Integers The University of Adelaide, School of Computer Science 19 November 2018 Two’s-Complement Signed Integers Given an n-bit number Range: –2n – 1 to +2n – 1 – 1 Example 1111,1111,1111,1111,1111,1111,1111,11002 = –1×231 + 1×230 + … + 1×22 +0×21 +0×20 = –2,147,483,648 + 2,147,483,644 = –410 Using 32 bits –2,147,483,648 to +2,147,483,647 Chapter 2 — Instructions: Language of the Computer — 11 Chapter 2 — Instructions: Language of the Computer

Two’s-Complement Signed Integers The University of Adelaide, School of Computer Science 19 November 2018 Two’s-Complement Signed Integers Most significant bit is the sign bit 1 for negative numbers 0 for non-negative numbers 2n – 1 can’t be represented Non-negative numbers have the same unsigned and two’s-complement representation Some specific numbers 0: 0000,0000,…,0000 –1: 1111,1111,…,1111 Most-negative: 1000,0000,…,0000 Most-positive: 0111,1111,…,1111 Chapter 2 — Instructions: Language of the Computer — 12 Chapter 2 — Instructions: Language of the Computer

The University of Adelaide, School of Computer Science 19 November 2018 Signed Negation Complement and add 1 Complement means 1 → 0, 0 → 1 Complement and add 1 → counterpart with opposite sign Two uses Given a negative decimal number, find its binary representation Given a negative binary number, find its positive counterpart Chapter 2 — Instructions: Language of the Computer — 13 Chapter 2 — Instructions: Language of the Computer

The University of Adelaide, School of Computer Science 19 November 2018 Examples Binary representation of -210 +2 = 0000,00102 –2 = 1111,11012 + 1 = 1111,11102 Decimal value of 1111,10112 -(1111,10112)=0000,01002+1=0000,01012 1111,10112=-510 Chapter 2 — Instructions: Language of the Computer — 14 Chapter 2 — Instructions: Language of the Computer

Range of 2’s complement A demo Start with 0 Keep adding 1 to the n-bit number Chapter 2 — Instructions: Language of the Computer — 15

Sign Extension of Signed Numbers The University of Adelaide, School of Computer Science 19 November 2018 Sign Extension of Signed Numbers Representing a number using more bits Preserve the numeric value In MIPS instruction set addi: extend immediate value lb, lh: extend loaded byte/halfword beq, bne: extend the displacement Replicate the sign bit to the left Examples: 8-bit to 16-bit +2: 0000,0010 => 0000,0000,0000,0010 –2: 1111,1110 => 1111,1111,1111,1110 Chapter 2 — Instructions: Language of the Computer — 16 Chapter 2 — Instructions: Language of the Computer

Extension of Unsigned Numbers Simply zero extension Add leading zeros Examples: 8-bit to 16-bit 210: 0000,0010 => 0000,0000,0000,0010 25410: 1111,1110 => 0000,0000,1111,1110 Chapter 2 — Instructions: Language of the Computer — 17

Addition/subtraction in base 16 Typically both operands and result have the same number of digits C=A+B ci= ai+bi+carryi-1 if ai+bi+carryi-1 < 16 ai+bi+carryi-1-16 otherwise C=A-B ai-bi-borrowi-1 if ai-bi-borrowi-1 > 0 16+ai-bi-borrowi-1 otherwise Chapter 2 — Instructions: Language of the Computer — 18

The University of Adelaide, School of Computer Science 19 November 2018 Overflow The result of an arithmetic operation is beyond the representation range An n-digit number has its range How to decide if overflow occurs Unsigned operations Check if there is a carry (in addition) or borrow (in subtraction) Signed operations Check the signs of the operands and the results Use examples Chapter 2 — Instructions: Language of the Computer — 19 Chapter 2 — Instructions: Language of the Computer

Overflow Addition with signed operands C = A + B A B C + No overflow - Don’t care Chapter 2 — Instructions: Language of the Computer — 20

Overflow Subtraction with signed operands C = A - B A B C + Don’t care No overflow - Overflow Chapter 2 — Instructions: Language of the Computer — 21