Ch3a- 2 EE/CS/CPE 3760 - Computer Organization  Seattle Pacific University Crunching Numbers Topics we need to explore Representing numbers on a computer.

Slides:



Advertisements
Similar presentations
ICS312 Set 2 Representation of Numbers and Characters.
Advertisements

HEXADECIMAL NUMBERS Code
Arithmetic & Logic Unit Does the calculations Everything else in the computer is there to service this unit Handles integers May handle floating point.
King Fahd University of Petroleum and Minerals
Data Representation Computer Organization &
Data Representation COE 205
Fixed-Point Arithmetics: Part I
1 Lecture 3 Bit Operations Floating Point – 32 bits or 64 bits 1.
Signed Numbers.
1 Binary Arithmetic, Subtraction The rules for binary arithmetic are: = 0, carry = = 1, carry = = 1, carry = = 0, carry =
Data Representation ICS 233
S. Barua – CPSC 240 CHAPTER 2 BITS, DATA TYPES, & OPERATIONS Topics to be covered are Number systems.
Signed Numbers CS208. Signed Numbers Until now we've been concentrating on unsigned numbers. In real life we also need to be able represent signed numbers.
Computer ArchitectureFall 2007 © August 29, 2007 Karem Sakallah CS 447 – Computer Architecture.
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.
Data Representation – Chapter 3 Sections 3-2, 3-3, 3-4.
1 Lecture 2: Number Systems Binary numbers Base conversion Arithmetic Number systems  Sign and magnitude  Ones-complement  Twos-complement Binary-coded.
Computer Organization & Programming Chapter2 Number Representation and Logic Operations.
Arithmetic for Computers
© Janice Regan, CMPT 128, Jan CMPT 128: Introduction to Computing Science for Engineering Students Integer Data representation Addition and Multiplication.
ACOE1611 Data Representation and Numbering Systems Dr. Costas Kyriacou and Dr. Konstantinos Tatas.
Data Representation – Binary Numbers
Computers Organization & Assembly Language
Computer Arithmetic Nizamettin AYDIN
CMPE 325 Computer Architecture II Cem Ergün Eastern Mediterranean University Integer Representation and the ALU.
1 CS/COE0447 Computer Organization & Assembly Language Chapter 3.
#1 Lec # 2 Winter EECC341 - Shaaban Positional Number Systems A number system consists of an order set of symbols (digits) with relations.
1 Homework Turn in HW2 tonight HW3 is on-line already Questions?
1 Digital Systems and Binary Numbers EE 208 – Logic Design Chapter 1 Sohaib Majzoub.
Lec 3: Data Representation Computer Organization & Assembly Language Programming.
Number Systems Spring Semester 2013Programming and Data Structure1.
Digital Logic Design Lecture 3 Complements, Number Codes and Registers.
ICS312 Set 1 Representation of Numbers and Characters.
Introduction to Computer Engineering ECE/CS 252, Fall 2010 Prof. Mikko Lipasti Department of Electrical and Computer Engineering University of Wisconsin.
ECE 301 – Digital Electronics Unsigned and Signed Numbers, Binary Arithmetic of Signed Numbers, and Binary Codes (Lecture #2)
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.
ECE 2110: Introduction to Digital Systems Signed Addition/Subtraction.
Operations on Bits Arithmetic Operations Logic Operations
ECE 331 – Digital System Design Representation and Binary Arithmetic of Negative Numbers and Binary Codes (Lecture #10) The slides included herein were.
AEEE2031 Data Representation and Numbering Systems.
Data Representation in Computer Systems. 2 Signed Integer Representation The conversions we have so far presented have involved only positive numbers.
Introduction to Microprocessors Chapter 2. Decimal or Base 10 Numbers  Have ten different digits (0-9)  It is a weighted number system. Each position.
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.
Bits, Data types, and Operations: Chapter 2 COMP 2610 Dr. James Money COMP
Chapter 4 Integer Data Representation. Unsigned Integers.
Number Representation and Arithmetic Circuits
In decimal we are quite familiar with placing a “-” sign in front of a number to denote that it is negative The same is true for binary numbers a computer.
MicroProcessors Lec. 4 Dr. Tamer Samy Gaafar. Course Web Page —
09/03/20161 Information Representation Two’s Complement & Binary Arithmetic.
Data Representation COE 301 Computer Organization Dr. Muhamed Mudawar
ECE 3110: Introduction to Digital Systems Signed Number Conversions and operations.
Data Representation COE 301 Computer Organization Prof. Muhamed Mudawar College of Computer Sciences and Engineering King Fahd University of Petroleum.
Floating Point Numbers Dr. Mohsen NASRI College of Computer and Information Sciences, Majmaah University, Al Majmaah
Data Representation COE 308 Computer Architecture
Addition and Subtraction
Bits, Data Types, and Operations
Chapter 2 Bits, Data Types, and Operations
Programming and Data Structure
Data Representation ICS 233
Lec 3: Data Representation
Data Representation.
Data Representation COE 301 Computer Organization
Data Representation – Chapter 3
1 The Hardware/Software Interface CSE351 Spring 2011 Module 3: Integers Monday, April 4, 2011.
Data Representation ICS 233
ECE 331 – Digital System Design
COMS 361 Computer Organization
Data Representation COE 308 Computer Architecture
Presentation transcript:

Ch3a- 2 EE/CS/CPE Computer Organization  Seattle Pacific University Crunching Numbers Topics we need to explore Representing numbers on a computer Negatives, too Hardware Alert! Building hardware to work with Floating Point numbers Building hardware to do logic and math And, Or Addition, Subtraction Comparisons Multiplication and Division

Ch3a- 3 EE/CS/CPE Computer Organization  Seattle Pacific University Representation All data on a computer is represented in binary 32 bits of data may be: 32-bit unsigned integer 4 ASCII characters Single-precision IEEE floating point number Who knows... data: As 32-bit unsigned integer: 2,303,067,432 As 32-bit 2’s complement integer: -1,991,899,864 As 4 ASCII characters: ‘??’, ‘F’, ENQ, ‘(‘ Note: Limited ASCII chart on p. 142

Ch3a- 4 EE/CS/CPE Computer Organization  Seattle Pacific University ASCII Representation of Numbers Terminal I/O (keyboard, display) only deals with ASCII characters Typically, strings of characters “We’re #1” --> 87,101,44,114,101,32,35,49,0 NULL Termination Note that the number ‘1’ is represented by 49 Numbers in I/O consist of their ASCII representations To output 103, use ASCII values 49, 48, 51 (3 bytes) Outputting 103 (one byte) won’t work ‘1’, ‘0’, ‘3’ code for ‘g’

Ch3a- 5 EE/CS/CPE Computer Organization  Seattle Pacific University Number Systems- Negative Numbers What about negative numbers? We need to represent numbers less than zero as well as zero or higher In n bits, we get 2 n combinations Make half positive, half negative... Sign bit: 0-->positive, 1-->negative 31 remaining bits for magnitude First method: use an extra bit for the sign

Ch3a- 6 EE/CS/CPE Computer Organization  Seattle Pacific University Sign and Magnitude Representation Two different representations for 0! Note: Example is shown for 4-bit numbers Inner numbers: Binary representation Seven Positive Numbers and “Positive” Zero Seven Negative Numbers and “Negative” Zero Number range for n bits = +/- 2 n-1 -1 Three low order bits represent the magnitude: 0 (000) through 7 (111) Two discontinuities High order bit is sign: 0 = positive (or zero), 1 = negative

Ch3a- 7 EE/CS/CPE Computer Organization  Seattle Pacific University Two’s Complement Representation Only one discontinuity now Note: Example is shown for 4-bit numbers Inner numbers: Binary representation Eight Positive Numbers Re-order Negative Numbers to Eliminate Discontinuities Only one zero One extra negative number Note: Negative numbers still have 1 for MSB

Ch3a- 8 EE/CS/CPE Computer Organization  Seattle Pacific University 2’s Complement Negation Method #1 To calculate the negative of a 2’s complement number: 1. Complement the entire number 2. Add one Examples: n = 0110= 6 complement n = = 68 n = = add 1 -n =1010 = -6 complement add 1 -n = = -68 complement add 1 -n = = 112 WARNING: This is for calculating the negative of a number. There is no such thing as “taking the 2’s complement of a number”.

Ch3a- 9 EE/CS/CPE Computer Organization  Seattle Pacific University 2’s Complement Negation Method #2 To calculate the negative of a 2’s complement number: 1. Starting at LSB, search to the left for the first one 2. Copy (unchanged) all of the bits to the right of the first one and the first one itself Examples: n = 0110= 6 -n = 10 = -6 copy complement n = = 68 -n = = -68 copy complement n = = n = = 112 copy complement 3. Complement the remaining bits

Ch3a- 10 EE/CS/CPE Computer Organization  Seattle Pacific University Adding Two’s Complement Numbers (-3) Just add the complete numbers together. Sign taken care of automatically. Ignore carry-out (for now) A carry out from sign bit does not necessarily mean overflow!

Ch3a- 11 EE/CS/CPE Computer Organization  Seattle Pacific University Overflow Add two positive numbers to get a negative number or two negative numbers to get a positive number Add two positive numbers to get a negative number or two negative numbers to get a positive number = = +7 Overflow cannot occur when adding a positive and negative number together Overflow occurs when crossing discontinuity Not a discontinuity - No Overflow A carryout from the MSB could mean crossing at either of these places – One is OK, one is Overflow

Ch3a- 12 EE/CS/CPE Computer Organization  Seattle Pacific University Detecting Overflow Overflow occurs when: We add two positive numbers and obtain a negative Looking at the sign bit (MSB): C in 0 C out C in 0 C out No overflowOverflow We add two negative numbers and obtain a positive C in 1 C out C in 1 C out OverflowNo Overflow Overflow when carry in to sign bit does not equal carry out C in C out Overflow C in 0 C out No Overflow C in 1 C out No Overflow 0

Ch3a- 13 EE/CS/CPE Computer Organization  Seattle Pacific University Signed and Unsigned operations Consider the following: $t0 = $t1 = execute: slt $s0, $t0, $t1 What’s the result? If we mean for $t0 to be 5 and $t1 to be 4,294,967,289 (treat as unsigned integers) then $s0 should get 1 If we mean for $t0 to be 5 and $t1 to be -7 (treat as signed integers) then $s0 should get 0 The default is to treat as signed integers Use sltu for unsigned integers

Ch3a- 14 EE/CS/CPE Computer Organization  Seattle Pacific University Using more bits What’s different between 4-bit 2’s complement and 32-bit? MSB has moved from bit 3 to bit 31! Copy MSB of original number into all remaining bits (32-bit 2’s comp.) (32-bit 2’s comp.) Sign Extension bit 2’s comp. To convert from 4-bit 2’s complement to 32-bit: Copy all 4 bits to 4 Least significant bits of the 32-bit number.

Ch3a- 15 EE/CS/CPE Computer Organization  Seattle Pacific University Loading a single byte from memory We can read a single 8-bit byte from memory location 3000 by using: lb $t0, 3000($0)# read byte at mem[3000] assuming mem[3000] = 0xF3, we get... $t0: 0xFFFFFFF3 (sign-extension for other 3 bytes) If we only want the byte at 3000 (without extension), used an unsigned load: lbu $t0, 3000($0)# read byte a mem[3000] $t0: 0x000000F3(no sign-extension) 0x prefix means Hex