March 2006 Saeid Nooshabadi

Slides:



Advertisements
Similar presentations
B261 Systems Architecture
Advertisements

Parul Polytechnic Institute Subject Code : Name Of Subject : Microprocessor and assembly language programming Name of Unit : Introduction to Microprossor.
Presented By Dr. Shazzad Hosain Asst. Prof. EECS, NSU
CONDITION CODE AND ARITHMETIC OPERATIONS – Microprocessor Asst. Prof. Dr. Choopan Rattanapoka and Asst. Prof. Dr. Suphot Chunwiphat.
HEXADECIMAL NUMBERS Code
ARITHMETIC, LOGIC INSTRUCTIONS, AND PROGRAMS
COMP3221 lec06-numbers-II.1 Saeid Nooshabadi COMP 3221 Microprocessors and Embedded Systems Lecture 6: Number Systems - II
COMP3221: Microprocessors and Embedded Systems--Lecture 4 1 COMP3221: Microprocessors and Embedded Systems Lecture 4: Number Systems (II)
1 Binary Arithmetic, Subtraction The rules for binary arithmetic are: = 0, carry = = 1, carry = = 1, carry = = 0, carry =
COMP3221 lec07-numbers-III.1 Saeid Nooshabadi COMP 3221 Microprocessors and Embedded Systems Lecture 7: Number Systems - III
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.
1 Lecture 2: Number Systems Binary numbers Base conversion Arithmetic Number systems  Sign and magnitude  Ones-complement  Twos-complement Binary-coded.
Binary numbers and arithmetic. ADDITION Addition (decimal)
Computer Organization & Programming Chapter2 Number Representation and Logic Operations.
1 Arithmetic and Logical Operations - Part II. Unsigned Numbers Addition in unsigned numbers is the same regardless of the base. Given a pair of bit sequences.
The 8051 Microcontroller and Embedded Systems
Computer Architecture Lecture 3: Logical circuits, computer arithmetics Piotr Bilski.
COMPUTER ORGANIZATIONS CSNB123 May 2014Systems and Networking1.
Complement Numbers. Outline  Negative Numbers Representation  Sign-and-magnitude  1s Complement  2s Complement  Comparison of Sign-and-Magnitude.
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
ECE 2110: Introduction to Digital Systems Signed Addition/Subtraction.
Operations on Bits Arithmetic Operations Logic Operations
CS Data representation 1 Ch. 2.1 Data Representation Unsigned and Signed Integers – representation, addition, subtraction.
Tutorial: ITI1100 Dewan Tanvir Ahmed SITE, UofO
Digital Logic Lecture 3 Binary Arithmetic By Zyad Dwekat The Hashemite University Computer Engineering Department.
MIPS ALU. Building from the adder to ALU ALU – Arithmetic Logic Unit, does the major calculations in the computer, including – Add – And – Or – Sub –
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=
CEC 220 Digital Circuit Design Binary Arithmetic & Negative Numbers Monday, January 13 CEC 220 Digital Circuit Design Slide 1 of 14.
Computer Architecture Lecture 15 Fasih ur Rehman.
CEC 220 Digital Circuit Design Binary Arithmetic & Negative Numbers Fri, Aug 28 CEC 220 Digital Circuit Design Slide 1 of 14.
Addition, Subtraction, Logic Operations and ALU Design
CHAPTER 6 ARITHMETIC, LOGIC INSTRUCTIONS, AND PROGRAMS.
ECE/CS 552: Arithmetic I Instructor:Mikko H Lipasti Fall 2010 University of Wisconsin-Madison Lecture notes partially based on set created by Mark Hill.
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.
MIPS ALU. Exercise – Design a selector? I need a circuit that takes two input bits, a and b, and a selector bit s. The function is that if s=0, f=a. if.
Computer Engineering page 1 Integer arithmetic Depends what you mean by “integer”. Assume at 3-bit string. –Then we define: zero = 000 one = 001 Use zero,
1 Integer Representations V1.0 (22/10/2005). 2 Integer Representations  Unsigned integer  Signed integer  Sign and magnitude  Complements  One’s.
Lecture 4: Digital Systems & Binary Numbers (4)
CHAPTER 9 COMPUTER ARITHMETIC - ALU
Negative Binary Numbers
Lecture 2 Topics Binary Arithmetic (Unsigned binary operands)
Negative Binary Numbers
ICS312 SET 7 Flags.
March 2006 Saeid Nooshabadi
The FLAGS Register An x bit means an unidentified value 9/12/2018
March 2006 Saeid Nooshabadi
Lecture 2 Topics Binary Arithmetic (Unsigned binary operands)
MIPS ALU.
COMP3221: Microprocessors and Embedded Systems
Arithmetic operations Programming
ECE/CS 552: Arithmetic and Logic
CS 235 Computer Organization & Assembly Language
MIPS ALU.
And conditional branching
University of Gujrat Department of Computer Science
ME 4447/6405 Microprocessor Control of Manufacturing Systems and
CPS120: Introduction to Computer Science
A 1-Bit Arithmetic Logic Unit
Arithmetic and Logic Chapter 5
ECE 171 Digital Circuits Chapter 2 Binary Arithmetic
ECE 331 – Digital System Design
Chapter 4 計算機算數.
ARITHMETIC, LOGIC INSTRUCTIONS, AND PROGRAMS
CSC 220: Computer Organization Signed Number Representation
Integer arithmetic Depends what you mean by "integer"
MIPS ALU.
MIPS ALU.
Ch. 5 – Intel 8086 – study details from Yu & Marut
Part IV The FLAGS Register
Presentation transcript:

March 2006 Saeid Nooshabadi saeid@unsw.edu.au ELEC2041 Microprocessors and Interfacing Lecture 7: Number Systems – II Extras http://webct.edtec.unsw.edu.au/ March 2006 Saeid Nooshabadi saeid@unsw.edu.au

Overview Condition Code Flag interpretation

Review: int and unsigned int in C With N bits we can represent 2N different Numbers: 2N numbers 0 to 2N - 1 :Only zero and Positive numbers 2N numbers -2N/2 to 0 to 2N/2- 1: Both Negative and positive numbers in 2’s Complement 0000 0001 0010 0011 0100 0101 0110 0111 1000 1001 1010 1011 1100 1101 1110 1111 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 1 2 3 4 5 6 7 -8 -7 -6 -5 -4 -3 -2 -1 Is 1000 > 0110 ? 1000 > 0110 if only +ve representation used 1000 < 0110 if both +ve and -ve representation in 2’s complement used

Review: Condition Flags Flags Arithmetic Instruction Negative Bit 31 of the result has been set (N=‘1’) Indicates a negative number in signed operations Zero Result of operation was zero (Z=‘1’) Carry Result was greater than 32 bits (C=‘1’) oVerflow Result was greater than 31 bits (V=‘1’) Indicates a possible corruption of the sign bit in signed numbers N flag SUB r0, r1, r2 where r1<r2 Z flag SUB r0, r1, r2 where r1=r2 (also used for results of logical operations) C flag ADD r0, r1, r2 where r1+r2>0xFFFFFFFF V flag ADD r0, r1, r2 where r1+r2>0x7FFFFFFF (if numbers are signed, ALU sign bit will be corrupted) (0x7FFFFFF+0x00000001=0x80000000) (answer okay for unsigned but wrong for signed)

`Experimentation with Condition Flags (#1/5) Indicate the changes in N, Z, C, V flags for the following arithmetic operations: (Assume 4 bit-numbers) 0010 0011 + 00101 =  Overflow, V = 0 = 0  Carry set, C = 0 Result Not Zero Z = 0 = 0  Result +Ve N = 0 N flag SUB r0, r1, r2 where r1<r2 Z flag SUB r0, r1, r2 where r1=r2 (also used for results of logical operations) C flag ADD r0, r1, r2 where r1+r2>0xFFFFFFFF V flag ADD r0, r1, r2 where r1+r2>0x7FFFFFFF (if numbers are signed, ALU sign bit will be corrupted) (0x7FFFFFF+0x00000001=0x80000000) (answer okay for unsigned but wrong for signed) Signed interpretation: 3 + 2 = 5. The number is within of the range of –8 to +7. No oVerflow (V) Unsigned interpretation: 3 + 2 = 5. The number is within the range of the range of 0 to +15. Carry NotSet, NoOverflow (C)

Experimentation with Condition Flags (#2/5) Indicate the changes in N, Z, C, V flags for the following arithmetic operations: (Assume 4 bit-numbers) 1110 1111 + 0010 10001 =  No Overflow, V = 0 NOTE: V = MSB Carry In (XOR) MSB Carry out = 1  Carry set, C = 1 Result Not Zero Z = 0 = 0  Result +Ve N = 0 N flag SUB r0, r1, r2 where r1<r2 Z flag SUB r0, r1, r2 where r1=r2 (also used for results of logical operations) C flag ADD r0, r1, r2 where r1+r2>0xFFFFFFFF V flag ADD r0, r1, r2 where r1+r2>0x7FFFFFFF (if numbers are signed, ALU sign bit will be corrupted) (0x7FFFFFF+0x00000001=0x80000000) (answer okay for unsigned but wrong for signed) Signed interpretation: -1 + 2 = 1. The number is within the range of –8 to +7. No oVerflow (V) Unsigned interpretation: 15 + 2 = 17. The number is out of the range of 0 to +15. Carry Set, Overflow (C)

`Experimentation with Condition Flags (#3/5) Indicate the changes in N, Z, C, V flags for the following arithmetic operations: (Assume 4 bit-numbers) 0110 0111 + 0010 01001   Overflow, V = 1 NOTE: V = MSB Carry In (XOR) MSB Carry out = 0  Carry set, C = 0 Result Not Zero Z = 0 = 1  Result -Ve N = 1 N flag SUB r0, r1, r2 where r1<r2 Z flag SUB r0, r1, r2 where r1=r2 (also used for results of logical operations) C flag ADD r0, r1, r2 where r1+r2>0xFFFFFFFF V flag ADD r0, r1, r2 where r1+r2>0x7FFFFFFF (if numbers are signed, ALU sign bit will be corrupted) (0x7FFFFFF+0x00000001=0x80000000) (answer okay for unsigned but wrong for signed) Signed interpretation: 7 + 2 = 9. The number is out of the range of –8 to +7. oVerflow (V) Unsigned interpretation: 7 + 2 = 9. The number is within the range of 0 to +15. Carry NotSet, NoOverflow (C)

Experimentation with Condition Flags (#4/5) Indicate the changes in N, Z, C, V flags for the following arithmetic operations: (Assume 4 bit-numbers) 1000 1110 + 1110 + 1001  1001 10111   OVerflow, V = 1 = 1  Carry set, C = 1 Result Not Zero Z = 0 = 0  Result +Ve N = 0 N flag SUB r0, r1, r2 where r1<r2 Z flag SUB r0, r1, r2 where r1=r2 (also used for results of logical operations) C flag ADD r0, r1, r2 where r1+r2>0xFFFFFFFF V flag ADD r0, r1, r2 where r1+r2>0x7FFFFFFF (if numbers are signed, ALU sign bit will be corrupted) (0x7FFFFFF+0x00000001=0x80000000) (answer okay for unsigned but wrong for signed) Signed interpretation: -2 - 7 = = -2 + (-7) =-9. The number is out of the range of –8 to +7. oVerflow (V) Unsigned interpretation: 14 + 9 = 23. The number is out of the range of 0 to +15. Carry Set, Overflow (C)

Experimentation with Condition Flags (#5/5) Indicate the changes in N, Z, C, V flags for the following arithmetic operations: (Assume 4 bit-numbers) 1000 1110 - 1110 + 0111  1001 10111   OVerflow, V = 1 = 1  Carry set, C = 1 Result Not Zero Z = 0 = 0  Result +Ve N = 0 Note: For Subtraction Carry Set means No Overflow (No Borrow) N flag SUB r0, r1, r2 where r1<r2 Z flag SUB r0, r1, r2 where r1=r2 (also used for results of logical operations) C flag ADD r0, r1, r2 where r1+r2>0xFFFFFFFF V flag ADD r0, r1, r2 where r1+r2>0x7FFFFFFF (if numbers are signed, ALU sign bit will be corrupted) (0x7FFFFFF+0x00000001=0x80000000) (answer okay for unsigned but wrong for signed) Signed interpretation: -2 - 7 = = -2 + (-7) =-9. The number is out of the range of –8 to +7. oVerflow (V) Unsigned interpretation: 14 - 7 = 7. The number is within the range of 0 to +15. Carry Set, NoOverflow (C) .

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: Addition: (Carry flag C = 0) NO OVERFLOW (Carry flag C = 1) OVERFLOW Subtraction: (Carry flag C = 0) OVERFLOW (Carry flag C = 1) NO OVERFLOW N flag SUB r0, r1, r2 where r1<r2 Z flag SUB r0, r1, r2 where r1=r2 (also used for results of logical operations) C flag ADD r0, r1, r2 where r1+r2>0xFFFFFFFF V flag ADD r0, r1, r2 where r1+r2>0x7FFFFFFF (if numbers are signed, ALU sign bit will be corrupted) (0x7FFFFFF+0x00000001=0x80000000) (answer okay for unsigned but wrong for signed)