COMP3221 lec07-numbers-III.1 Saeid Nooshabadi COMP 3221 Microprocessors and Embedded Systems Lecture 7: Number Systems - III

Slides:



Advertisements
Similar presentations
Assembly Language for Intel-Based Computers, 4 th Edition Chapter 1: Basic Concepts (c) Pearson Education, All rights reserved. You may modify and.
Advertisements

HEXADECIMAL NUMBERS Code
CS 61C L02 Number Representation (1) Garcia, Spring 2004 © UCB Lecturer PSOE Dan Garcia inst.eecs.berkeley.edu/~cs61c CS61C.
COMP3221: Microprocessors and Embedded Systems--Lecture 1 1 COMP3221: Microprocessors and Embedded Systems Lecture 3: Number Systems (I)
COMP3221 lec05-numbers-I.1 Saeid Nooshabadi COMP 3221 Microprocessors and Embedded Systems Lecture 5: Number Systems – I
CS 61C L02 Number Representation (1)Harvey / Wawrzynek Fall 2003 © UCB 8/27/2003  Brian Harvey ( John Wawrzynek  (Warznek) (
Data Representation Computer Organization &
COMP3221 lec06-numbers-II.1 Saeid Nooshabadi COMP 3221 Microprocessors and Embedded Systems Lecture 6: Number Systems - II
TK 2633 Microprocessor & Interfacing Lecture 3: Introduction to 8085 Assembly Language Programming (2) 1 Prepared By: Associate Prof. Dr Masri Ayob.
CS 151 Digital Systems Design Lecture 3 More Number Systems.
Data Representation COE 205
Assembly Language and Computer Architecture Using C++ and Java
Cs 61C L8 Char.1 Patterson Spring 99 ©UCB CS61C Characters and Floating Point Lecture 8 February 12, 1999 Dave Patterson (http.cs.berkeley.edu/~patterson)
Introduction to Programming with Java, for Beginners
CS 61C L02 Number Representation (1) Garcia, Spring 2004 © UCB Lecturer PSOE Dan Garcia inst.eecs.berkeley.edu/~cs61c CS61C.
Assembly Language and Computer Architecture Using C++ and Java
Assembly Language for Intel-Based Computers, 4th Edition
COMP3221: Microprocessors and Embedded Systems--Lecture 4 1 COMP3221: Microprocessors and Embedded Systems Lecture 4: Number Systems (II)
Assembly Language for Intel-Based Computers, 5 th Edition Chapter 1: Basic Concepts (c) Pearson Education, All rights reserved. You may modify.
Number Representation (1) Fall 2005 Lecture 12: Number Representation Integers and Computer Arithmetic.
Data Representation ICS 233
+ CS 325: CS Hardware and Software Organization and Architecture Integers and Arithmetic Part 4.
Codes and number systems Introduction to Computer Yung-Yu Chuang with slides by Nisan & Schocken ( ) and Harris & Harris (DDCA)
Assembly Language for Intel-Based Computers, 5 th Edition Chapter 1: Basic Concepts (c) Pearson Education, All rights reserved. You may modify.
Arithmetic for Computers
CENG 311 Machine Representation/Numbers
Computers Organization & Assembly Language
CMPE 325 Computer Architecture II Cem Ergün Eastern Mediterranean University Integer Representation and the ALU.
CSU0014 Assembly Languages Homepage: Textbook: Kip R. Irvine, Assembly Language for Intel-Based Computers,
Summer 2014 Chapter 1: Basic Concepts. Irvine, Kip R. Assembly Language for Intel-Based Computers 6/e, Chapter Overview Welcome to Assembly Language.
Assembly Language for x86 Processors 7th Edition
IT253: Computer Organization
Chapter 1: Basic Concepts
1 Digital Systems and Binary Numbers EE 208 – Logic Design Chapter 1 Sohaib Majzoub.
Copyright © The McGraw-Hill Companies, Inc. Permission required for reproduction or display. Idea 1: Bits Two states in a digital machine: 1.presence of.
Lec 3: Data Representation Computer Organization & Assembly Language Programming.
ECEN2102 Digital Logic Design Lecture 1 Numbers Systems Abdullah Said Alkalbani University of Buraimi.
Number Systems Spring Semester 2013Programming and Data Structure1.
Digital Logic Design Lecture 3 Complements, Number Codes and Registers.
10-Sep Fall 2001: copyright ©T. Pearce, D. Hutchinson, L. Marshall Sept Representing Information in Computers:  numbers: counting numbers,
Chapter 19 Number Systems. Irvine, Kip R. Assembly Language for Intel-Based Computers, Translating Languages English: Display the sum of A times.
Ch3a- 2 EE/CS/CPE Computer Organization  Seattle Pacific University Crunching Numbers Topics we need to explore Representing numbers on a computer.
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 1 Representing Data in a Computer. 1.1 Binary and Hexadecimal Numbers.
Data Representation COE 301 Computer Organization Dr. Muhamed Mudawar
Data Representation COE 301 Computer Organization Prof. Muhamed Mudawar College of Computer Sciences and Engineering King Fahd University of Petroleum.
Data Representation COE 308 Computer Architecture
Bits, Data Types, and Operations
Programming and Data Structure
NUMBER SYSTEMS.
Data Representation ICS 233
Lec 3: Data Representation
Data Representation.
Number Representation
Data Representation Binary Numbers Binary Addition
Microprocessor Systems Design I
Morgan Kaufmann Publishers
Microprocessor Systems Design I
COMP2121: Microprocessors and Interfacing
March 2006 Saeid Nooshabadi
March 2006 Saeid Nooshabadi
COMP3221: Microprocessors and Embedded Systems
Data Representation COE 301 Computer Organization
Data Representation ICS 233
March 2006 Saeid Nooshabadi
Review In last lecture, done with unsigned and signed number representation. Introduced how to represent real numbers in float format.
Data Representation COE 308 Computer Architecture
Presentation transcript:

COMP3221 lec07-numbers-III.1 Saeid Nooshabadi COMP 3221 Microprocessors and Embedded Systems Lecture 7: Number Systems - III August, 2003 Saeid Nooshabadi

COMP3221 lec07-numbers-III.2 Saeid Nooshabadi Overview °Condition Code Flag interpretation °Characters and Strings °In Conclusion

COMP3221 lec07-numbers-III.3 Saeid Nooshabadi Review: int and unsigned int in C °With N bits we can represent 2 N different Numbers: 2 N numbers 0 to 2 N - 1 :Only zero and Positive numbers 2 N numbers -2 N /2 to 0 to 2 N /2- 1: Both Negative and positive numbers in 2’s Complement Is 1000 > 0110 ? 1000 > 0110 if only +ve representation used 1000 < 0110 if both +ve and -ve representation in 2’s complement used

COMP3221 lec07-numbers-III.4 Saeid Nooshabadi FlagsArithmetic Instruction NegativeBit 31 of the result has been set (N=‘1’)Indicates a negative number in signed operations ZeroResult of operation was zero (Z=‘1’) CarryResult was greater than 32 bits (C=‘1’) oVerflowResult was greater than 31 bits (V=‘1’)Indicates a possible corruption of the sign bit in signed numbers Review: Condition Flags

COMP3221 lec07-numbers-III.5 Saeid Nooshabadi Indicate the changes in N, Z, C, V flags for the following arithmetic operations: (Assume 4 bit-numbers) Experimentation with Condition Flags (#1/4) = 1  Carry set, C = 1 = 0  Result +Ve N = 0 Result Not Zero Z = 0 Signed interpretation: = 1. The number is within the range of –8 to +7. No oVerflow (V), Ignore Carry out. Unsigned interpretation: = 17. The number is out of the range of 0 to +15. Carry Set and oVerflow Not set. Indication for overflow in unsigned. =  No Overflow, V = 0 NOTE: V = MSB Carry In (XOR) MSB Carry out

COMP3221 lec07-numbers-III.6 Saeid Nooshabadi Indicate the changes in N, Z, C, V flags for the following arithmetic operations: (Assume 4 bit-numbers) `Experimentation with Condition Flags (#2/4) = 0  Carry set, C = 0 = 1  Result -Ve N = 1 Result Not Zero Z = 0 Signed interpretation: = 9. The number is out of the range of – 8 to +7. oVerflow (V), Ignore Carry out. Unsigned interpretation: = 9. The number is within the range of 0 to +15. Carry Not set and oVerflow Set. Indication for No overflow in unsigned.   Overflow, V = 1 NOTE: V = MSB Carry In (XOR) MSB Carry out

COMP3221 lec07-numbers-III.7 Saeid Nooshabadi Indicate the changes in N, Z, C, V flags for the following arithmetic operations: (Assume 4 bit-numbers)  Experimentation with Condition Flags (#3/4)   OVerflow, V = 1 = 1  Carry set, C = 1 = 0  Result +Ve N = 0 Result Not Zero Z = 0 Signed interpretation: = = -2 + (-7) =-9. The number is out of the range of –8 to +7. oVerflow (V), Ignore Carry out. Unsigned interpretation: = 7. The number is in of the range of 0 to +15. Carry Set and oVerflow Set. Indication for No overflow in unsigned.

COMP3221 lec07-numbers-III.8 Saeid Nooshabadi Indicate the changes in N, Z, C, V flags for the following arithmetic operations: (Assume 4 bit-numbers) `Experimentation with Condition Flags (#4/4) =  Overflow, V = 0 = 0  Carry set, C = 0 = 0  Result +Ve N = 0 Result Not Zero Z = 0 Signed interpretation: = 5. The number is within of the range of –8 to +7. No oVerflow (V), Ignore Carry out. Unsigned interpretation: = 5. The number is within the range of 0 to +15. Carry Not set and oVerflow Not set. Indication for No overflow in unsigned.

COMP3221 lec07-numbers-III.9 Saeid Nooshabadi Signed /Unsigned Overflow Summary Signed Arithmetic overflow Condition: oVerflow flag V = 0 NO OVERFLOW oVerflow flag V = 1 OVERFLOW NOTE: V = MSB Carry In (XOR) MSB Carry out UnSigned Arithmetic overflow Condition: Oveflow: (oVerflow flag V = 0) AND (Carry flag C = 0) NO OVERFLOW (oVerflow flag V = 0) AND (Carry flag C = 1) OVERFLOW (oVerflow flag V = 1) AND (Carry flag C = 0) NO OVERFLOW (oVerflow flag V = 1) AND (Carry flag C = 1) NO OVERFLOW

COMP3221 lec07-numbers-III.10 Saeid Nooshabadi Sign Extension °Consider: 1111 = -1 in 4-bit representation = -1 in 8-bit representation = -1 in 16-bit representation 2’s comp. negative number has infinite 1s 0111 = 7 in 4-bit representation = 7 in 8-bit representation = 7 in 16-bit representation 2’s comp. positive number has infinite 0s Bit representation hides leading bits

COMP3221 lec07-numbers-III.11 Saeid Nooshabadi Two’s comp. shortcut: Sign extension °Convert 2’s complement number using n bits to more than n bits °Simply replicate the most significant bit (sign bit) of smaller to fill new bits 2’s comp. positive number has infinite 0s 2’s comp. negative number has infinite 1s Bit representation hides leading bits; sign extension restores some of them 16-bit -4 ten to 32-bit: two two

COMP3221 lec07-numbers-III.12 Saeid Nooshabadi Beyond Integers (Characters) ° 8-bit bytes represent characters, nearly every computer uses American Standard Code for Information Interchange (ASCII) No. char Uppercase + 32 = Lowercase (e.g, B+32=b) tab=9, carriage return=13, backspace=8, Null=0 (Table in CD-ROM)

COMP3221 lec07-numbers-III.13 Saeid Nooshabadi Strings °Characters normally combined into strings, which have variable length e.g., “Cal”, “M.A.D”, “COMP3221” °How represent a variable length string? 1) 1st position of string reserved for length of string (Pascal) 2) an accompanying variable has the length of string (as in a structure) 3) last position of string is indicated by a character used to mark end of string (C) °C uses 0 (Null in ASCII) to mark end of string

COMP3221 lec07-numbers-III.14 Saeid Nooshabadi No. char Example String ° How many bytes to represent string “Popa”? °What are values of the bytes for “Popa”? °80, 111, 112, 97, 0DEC °50, 6F, 70, 61, 0 HEX

COMP3221 lec07-numbers-III.15 Saeid Nooshabadi Strings in C: Example °String simply an array of char void strcpy (char x[], char y[]){ int i = 0; /* declare,initialize i*/ while ((x[i] = y[i]) != ’\0’) /* 0 */ i = i + 1; /* copy and test byte */ }

COMP3221 lec07-numbers-III.16 Saeid Nooshabadi What about non-Roman Alphabet? °Unicode, universal encoding of the characters of most human languages Java uses Unicode needs 16 bits to represent a character 16-bits called half word in ARM

COMP3221 lec07-numbers-III.17 Saeid Nooshabadi ASCII v. Binary °Why not ASCII computers vs. binary computers? Harder to build hardware for add, subtract, multiply, divide Memory space to store numbers °How many bytes to represent 1 billion? °ASCII: “ ” => 11 bytes °Binary: => 4 bytes °up to 11/4 or almost 3X expansion of data size

COMP3221 lec07-numbers-III.18 Saeid Nooshabadi What else is useful to represent? °Numbers, Characters, logicals,... °Addresses °Commands (operations) example: -0 => clap your hands -1 => snap your fingers -2 => slap your hands down execute: another example -0 => add -1 => subtract -2 => compare -3 => multiply

COMP3221 lec07-numbers-III.19 Saeid Nooshabadi How can we represent a machine instruction? °Some bits for the operation °Some bits for the address of each operand °Some bits for the address of the result °Where could we put these things called instructions? operation result addr op1 addr op2 addr 0N-1 d = x + yadd d x y

COMP3221 lec07-numbers-III.20 Saeid Nooshabadi The Stored Program Computer °Memory holds instructions and data as bits °Instructions are fetched from memory and executed operands fetched, manipulated, and stored °Example 4-digit Instruction operation: 0 => add, 1 => sub result address op1 address op2 address °Example Data 4 digit unsigned value °What’s in memory after executing 0,1,2? operation result addr op1 addr op2 addr 0 => add 1 => subtract 2 => compare 3 => multiply

COMP3221 lec07-numbers-III.21 Saeid Nooshabadi So what’s it all mean? °We can write a program that will translate strings of ‘characters’ into ‘computer instructions’ called a compiler or an assembler °We can load these particular bits into the computer and execute them. may manipulate numbers, characters, pixels... (application) may translate strings to instructions (compiler) may load and run more programs (operating system)

COMP3221 lec07-numbers-III.22 Saeid Nooshabadi To remember °We represent “things” in computers as particular bit patterns numbers, characters,...(data) -base, digits, positional notation -unsigned, 2s complement, 1s complement addresses(where to find it) instructions(what to do) °Computer operations on the representation correspond to real operations on the real thing representation of 2 plus representation of 3 = representation of 5 °two big ideas already! Pliable Data: a program determines what it is Stored program concept: instructions are just data

COMP3221 lec07-numbers-III.23 Saeid Nooshabadi And in Conclusion... °2’s complement universal in computing: cannot avoid, so learn °Overflow: numbers infinite but computers finite, so errors occur °Computers provide help to detect overflow °Condition code flags N, Z, C and V provide help to deal with arithmetic computation and interpretation in signed and unsigned representation.