COMP3221: Microprocessors and Embedded Systems--Lecture 4 1 COMP3221: Microprocessors and Embedded Systems Lecture 4: Number Systems (II)

Slides:



Advertisements
Similar presentations
COMP3221: Microprocessors and Embedded Systems
Advertisements

Week 3. Assembly Language Programming  Difficult when starting assembly programming  Have to work at low level  Use processor instructions >Requires.
Assembly Language for Intel-Based Computers, 4 th Edition Chapter 1: Basic Concepts (c) Pearson Education, All rights reserved. You may modify and.
COMP3221: Microprocessors and Embedded Systems Final Exam Lecturer: Hui Wu Session 1, 2005.
COMP3221: Microprocessors and Embedded Systems
COMP3221: Microprocessors and Embedded Systems--Lecture 7 1 COMP3221: Microprocessors and Embedded Systems Lecture 7: Arithmetic and logic Instructions.
COMP3221: Microprocessors and Embedded Systems--Lecture 1 1 COMP3221: Microprocessors and Embedded Systems Lecture 3: Number Systems (I)
COMP3221: Microprocessors and Embedded Systems--Lecture 7 1 COMP3221: Microprocessors and Embedded Systems Lecture 7: Arithmetic and logic Instructions.
COMP3221: Microprocessors and Embedded Systems Lecture 14: Floating Point Numbers Lecturer: Hui Wu Session 2, 2004.
CS 61C L02 Number Representation (1)Harvey / Wawrzynek Fall 2003 © UCB 8/27/2003  Brian Harvey ( John Wawrzynek  (Warznek) (
COMP3221: Microprocessors and Embedded Systems--Lecture 8 1 COMP3221: Microprocessors and Embedded Systems Lecture 8: Program Control Instructions
COMP3221: Microprocessors and Embedded Systems Lecture 2: Instruction Set Architecture (ISA) Lecturer: Hui Wu Session.
COMP3221 lec06-numbers-II.1 Saeid Nooshabadi COMP 3221 Microprocessors and Embedded Systems Lecture 6: Number Systems - II
CS 61C L02 Number Representation (1) Garcia, Spring 2004 © UCB Lecturer PSOE Dan Garcia inst.eecs.berkeley.edu/~cs61c CS61C.
ARM programmer’s model and assembler Embedded Systems Programming.
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.
COMP3221 lec07-numbers-III.1 Saeid Nooshabadi COMP 3221 Microprocessors and Embedded Systems Lecture 7: Number Systems - III
+ CS 325: CS Hardware and Software Organization and Architecture Integers and Arithmetic Part 4.
Microprocessor Systems Design I
Computer ArchitectureFall 2007 © August 29, 2007 Karem Sakallah CS 447 – Computer Architecture.
Codes and number systems Introduction to Computer Yung-Yu Chuang with slides by Nisan & Schocken ( ) and Harris & Harris (DDCA)
COMP201 Computer Systems Number Representation. Number Representation Introduction Number Systems Integer Representations Examples  Englander Chapter.
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
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
Java Primitives The Smallest Building Blocks of the Language (corresponds with Chapter 2)
ACOE2511 ACOE251/AEEC335 -Assembly Language for the 80X86/Pentium Intel Microprocessors Lecturer: Dr. Konstantinos Tatas.
1 Introduction Chapter 1 n What is Assembly Language? n Data Representation.
Lec 3: Data Representation Computer Organization & Assembly Language Programming.
Number Systems Spring Semester 2013Programming and Data Structure1.
10-Sep Fall 2001: copyright ©T. Pearce, D. Hutchinson, L. Marshall Sept Representing Information in Computers:  numbers: counting numbers,
ECE 301 – Digital Electronics Unsigned and Signed Numbers, Binary Arithmetic of Signed Numbers, and Binary Codes (Lecture #2)
Introduction to AVR Chapter 1
CS Data representation 1 Ch. 2.1 Data Representation Unsigned and Signed Integers – representation, addition, subtraction.
Chapter 19 Number Systems. Irvine, Kip R. Assembly Language for Intel-Based Computers, Translating Languages English: Display the sum of A times.
Microprocessor Technique Binary codes. Lecture 2 1/47 Binary codes in microprocessor technique Integer arithmetic Fix-point arithmetic Floating-point.
ACOE2511 Assembly Language for the 80X86/Pentium Intel Microprocessors Lecturer: Dr. Konstantinos Tatas.
Ch3a- 2 EE/CS/CPE Computer Organization  Seattle Pacific University Crunching Numbers Topics we need to explore Representing numbers on a computer.
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.
Chapter 4 Integer Data Representation. Unsigned Integers.
Computer Architecture Lecture 15 Fasih ur Rehman.
Arithmetic Operations
COMP3221: Microprocessors and Embedded Systems--Lecture 10 1 COMP3221: Microprocessors and Embedded Systems Lecture 10: Shift and Bit-set Instructions.
Types Chapter 2. C++ An Introduction to Computing, 3rd ed. 2 Objectives Observe types provided by C++ Literals of these types Explain syntax rules for.
ECE 447: Lecture 11 Introduction to Programming in Assembly Language.
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.
Chapter 1 Representing Data in a Computer. 1.1 Binary and Hexadecimal Numbers.
Computer and Information Sciences College / Computer Science Department CS 206 D Computer Organization and Assembly Language.
Lecture 7. Subtractor Prof. Taeweon Suh Computer Science & Engineering Korea University COSE221, COMP211 Logic Design.
Lec 3: Data Representation
COMP2121: Microprocessors and Interfacing
Microprocessor Systems Design I
Microprocessor Systems Design I
COMP2121: Microprocessors and Interfacing
March 2006 Saeid Nooshabadi
COMP3221: Microprocessors and Embedded Systems
ME 4447/6405 Microprocessor Control of Manufacturing Systems and
March 2006 Saeid Nooshabadi
COMP3221: Microprocessors and Embedded Systems
Part I Data Representation and 8086 Microprocessors
Presentation transcript:

COMP3221: Microprocessors and Embedded Systems--Lecture 4 1 COMP3221: Microprocessors and Embedded Systems Lecture 4: Number Systems (II) Lecturer: Hui Wu Session 2, 2005

COMP3221: Microprocessors and Embedded Systems--Lecture 4 2 Overview Overflow in 2’s complement addition Comparison in signed and unsigned numbers Condition flags Characters and strings

COMP3221: Microprocessors and Embedded Systems--Lecture 4 3 ° Example 1: 20 – 4 = 16 ° Assume 8 bit architecture. 20 – 4 = 20 + (–4) = two – two = two two = two Carry Most significant bit (msb) No overflow. Two’s Complement’s Arithmetic Examples

COMP3221: Microprocessors and Embedded Systems--Lecture 4 4 ° Example 2: –127 – 2 = – 129? ° – 127 – 2 = – two – two = two two = two Carry msb Overflow Two’s Complement’s Arithmetic Examples

COMP3221: Microprocessors and Embedded Systems--Lecture 4 5 ° Example 3: = 129? ° = two two = two two = two msb Overflow Two’s Complement’s Arithmetic Examples

COMP3221: Microprocessors and Embedded Systems--Lecture 4 6 When Overflow Occurs? The ‘two’s complement overflow’ occurs when: both the msb’s being added are 0 and the msb of the result is 1 both the msb’s being added are 1 and the msb of the result is 0

COMP3221: Microprocessors and Embedded Systems--Lecture 4 7 ° C declaration int Declares a signed number Uses two’s complement ° C declaration unsigned int Declares a unsigned number Treats 32-bit number as unsigned integer, so most significant bit is part of the number, not a sign bit ° NOTE: Hardware does all arithmetic in 2’s complement. It is up to programmer to interpret numbers as signed or unsigned. Signed vs. Unsigned Numbers

COMP3221: Microprocessors and Embedded Systems--Lecture 4 8 ° AVR microcontrollers support only 8 bit signed and unsigned integers. ° Multi-byte signed and unsigned integers can be implemented by software. ° Question: How to compute two two on AVR? Signed and Unsigned Numbers in AVR

COMP3221: Microprocessors and Embedded Systems--Lecture 4 9 ° Solution: Four-byte integer addition can be done by using four one-byte integer additions taking carries into account (lowest bytes are added first) = Carry bits The result is two Signed and Unsigned Numbers in AVR (Cont.)

COMP3221: Microprocessors and Embedded Systems--Lecture 4 10 X = two Y = two Is X > Y? –unsigned: YES –signed: NO Signed v. Unsigned Comparison

11 Signed v. Unsigned Comparison (Hardware Help) ° X = two ° Y = two ° Is X > Y? Do the Subtraction X – Y and check result X – Y = two – two = two two = two Hardware needs to keep a special bit ( S flag in AVR) which indicates the result of signed comparison, and a special bit (C flag in AVR) which indicates the result of unsigned comparison.

COMP3221: Microprocessors and Embedded Systems--Lecture 4 12 Numbers are stored at addresses ° Memory is a place to store bits ° A word is a fixed number of bits (eg, 16 in AVR assembler) at an address ° Addresses have fixed number of bits ° Addresses are naturally represented as unsigned numbers ° How multi-byte numbers are stored in memory is determined by the endianness. ° On AVR, programmers choose the endianess. 0x0000 0x0001 0x0002 0xF…F

13 Status Flags in Program Status Register CZVNSH The Processor Status Register in AVR C: Its meaning depends on the operation. For addition X+Y, it is the carry from the most significant bit. In other words, C= Rd7 Rr7 +Rr7 NOT(R7) + NOT(R7) Rd7, where Rd7 is bit 7 of x, Rr7 is bit 7 of y, R7 is bit 7 of x+y, is the logical AND and + is the logical OR. For subtraction x-y, where x and y are unsigned integer, it indicates if y<x. If y<x, the C=1; otherwise, C=0. In other words, C = NOT(Rd7) Rr7+ Rr7 R7 +R7 NOT(Rd7).

14 Status Flags in Program Status Register CZVNSH The Processor Status Register in AVR Z: 1 indicates a zero result after a arithmetic or logical operation. N: the most significant bit of the result. V: 1 indicates two’s complement oVerflow. S: Sign flag—exclusive OR between N and V. 1: negative result. 0: non-negative result. H: Half carry flag.

COMP3221: Microprocessors and Embedded Systems--Lecture 4 15 Experimentation with Condition Flags (#1/3) Indicate the changes in N, Z, C, V flags for the following arithmetic operations: (Assume 4 bit-numbers) = N=1 V=0 Z=0 C=0 S=1 H=1

COMP3221: Microprocessors and Embedded Systems--Lecture 4 16 Experimentation with Condition Flags (#2/3) Indicate the changes in N, Z, C, V flags for the following arithmetic operations: (Assume 4 bit-numbers) = N=0 V=1 Z=0 C=1 S=1 H=1

COMP3221: Microprocessors and Embedded Systems--Lecture 4 17 Experimentation with Condition Flags (#3/3) Indicate the changes in N, Z, C, V flags for the following arithmetic operations: (Assume 4 bit-numbers) – = = N=1 V=0 Z=0 C=1 S=1 H=0

COMP3221: Microprocessors and Embedded Systems--Lecture 4 18 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

COMP3221: Microprocessors and Embedded Systems--Lecture 4 19 Strings ° Characters normally combined into strings, which have variable length e.g., “Cal”, “M.A.D”, “COMP3221” ° How to 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 the end of a string

COMP3221: Microprocessors and Embedded Systems--Lecture 4 20 ° How many bytes to represent string “Popa”? ° What are values of the bytes for “Popa”? Example String No. char ° 80, 111, 112, 97, 0 DEC ° 50, 6F, 70, 61, 0 HEX

COMP3221: Microprocessors and Embedded Systems--Lecture 4 21 Strings in C: Example ° String simply an array of char void strcpy (char x[],char y[]) { int i=0; /* declare and initialize i*/ while ((x[i]=y[i])!=’\0’) /* 0 */ i=i+1; /* copy and test byte */ }

COMP3221: Microprocessors and Embedded Systems--Lecture 4 22 String in AVR Assembly Language.db “Hello\n” ; This is equivalent to.db ‘H’, ‘e’, ‘l’, ‘l’, ‘o’, ‘\n’ What does the following instruction do? ldi r4, ‘1’

COMP3221: Microprocessors and Embedded Systems--Lecture 4 23 How to Represent A Machine Instruction? ° Some bits for the operation (addition, subtraction etc.). ° Some bits for each operand (the maximum number of operands in an instruction is determined by the instruction set). ° Example: operand 2operand 1operation 8 bits 4 bits 4 bits ° Will cover the details in next lecture.

COMP3221: Microprocessors and Embedded Systems--Lecture 4 24 Reading Material 1.Appendix A in Microcontrollers ands Microcomputers.