Arithmetic Instructions and Programs. Outlines Range of numbers in 8051 unsigned data Range of numbers in 8051 unsigned data Addition & subtraction instructions.

Slides:



Advertisements
Similar presentations
Week 3. Assembly Language Programming  Difficult when starting assembly programming  Have to work at low level  Use processor instructions >Requires.
Advertisements

MOV Instruction MOV destination, source ; copy source to dest. MOV A,#55H ;load value 55H into reg. A MOV R0,A ;copy contents of A into R0 ;(now A=R0=55H)
Introduction to Computer Engineering by Richard E. Haskell BCD Arithmetic Module M16.5 Section 10.4.
Arithmetic in Computers Chapter 4 Arithmetic in Computers2 Outline Data representation integers Unsigned integers Signed integers Floating-points.
DAT2343 Summary of Standard Data Encoding © Alan T. Pinck / Algonquin College; 2003.
Msc. Ivan A. Escobar Broitman Microprocessors 1 1 The 8051 Instruction Set.
ARITHMETIC, LOGIC INSTRUCTIONS, AND PROGRAMS
Lecture - 2 Number systems and computer data formats
Addition and Subtraction. Outline Arithmetic Operations (Section 1.2) – Addition – Subtraction – Multiplication Complements (Section 1.5) – 1’s complement.
Princess Sumaya Univ. Computer Engineering Dept. Chapter 3:
Princess Sumaya Univ. Computer Engineering Dept. Chapter 3: IT Students.
CMP 101 Fundamentals of Computer and programming in C Rohit Khokher.
Chapter 6 Arithmetic Instructions and Programs
© 2006 Pearson Education, Upper Saddle River, NJ All Rights Reserved.Brey: The Intel Microprocessors, 7e Chapter 5 Arithmetic and Logic Instructions.
1 Lecture 8: Binary Multiplication & Division Today’s topics:  Addition/Subtraction  Multiplication  Division Reminder: get started early on assignment.
DIGITAL SYSTEMS TCE1111 Representation and Arithmetic Operations with Signed Numbers Week 6 and 7 (Lecture 1 of 2)
1 Lecture 2: Number Systems Binary numbers Base conversion Arithmetic Number systems  Sign and magnitude  Ones-complement  Twos-complement Binary-coded.
The M68HC11 Basic Instruction Set Basic Arithmetic Instructions
Binary Representation - Shortcuts n Negation x + x = 1111…1111 two = -1 (in 2’s complement) Therefore, -x = x + 1 n Sign Extension o Positive numbers :
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
Khaled A. Al-Utaibi  Introduction  Arithmetic Instructions  Basic Logical Instructions  Shift Instructions  Rotate Instructions.
#1 Lec # 2 Winter EECC341 - Shaaban Positional Number Systems A number system consists of an order set of symbols (digits) with relations.
Flag Control instructions CLC clear carry flag CF = 0 STC set carry flag CF= 1 CMC complement carry flag [CF] CF.
CHAPTER 1 INTRODUCTION NUMBER SYSTEMS AND CONVERSION.
Number Systems. Today Decimal Hexadecimal Binary –Unsigned Binary –1’s Complement Binary –2’s Complement Binary.
Number Systems ELEC 311 Digital Logic and Circuits Dr. Ron Hayne Images Courtesy of Cengage Learning.
ASCII and BCD Arithmetic Chapter 11 S. Dandamudi.
Chapter four – The 80x86 Instruction Set Principles of Microcomputers 2015年10月19日 2015年10月19日 2015年10月19日 2015年10月19日 2015年10月19日 2015年10月19日 1 Chapter.
University Of Engineering And Technology Taxila REF::NATIONAL TAIWANOCEAN UNIVERSITY 國立台灣海洋大學 Chapter 3 JUMP, LOOP and CALL Instructions.
ECE 2110: Introduction to Digital Systems Signed Addition/Subtraction.
Operations on Bits Arithmetic Operations Logic Operations
Princess Sumaya Univ. Computer Engineering Dept. Chapter 3:
Microprocessor Technique Binary codes. Lecture 2 1/47 Binary codes in microprocessor technique Integer arithmetic Fix-point arithmetic Floating-point.
Assembly Language for Intel-Based Computers, 4 th Edition Unpacked and Packed Integers (c) Pearson Education, All rights reserved. You may modify.
Bits, Data types, and Operations: Chapter 2 COMP 2610 Dr. James Money COMP
Chapter 4 Integer Data Representation. Unsigned Integers.
CEC 220 Digital Circuit Design Binary Arithmetic & Negative Numbers Monday, January 13 CEC 220 Digital Circuit Design Slide 1 of 14.
CEC 220 Digital Circuit Design Binary Arithmetic & Negative Numbers Fri, Aug 28 CEC 220 Digital Circuit Design Slide 1 of 14.
Division. Just as multiplication can be expressed as a series of additions, division can be seen as a series of subtractions. 21 ÷ 7 asks how many times.
DIGITAL SYSTEMS Number systems & Arithmetic Rudolf Tracht and A.J. Han Vinck.
CHAPTER 6 ARITHMETIC, LOGIC INSTRUCTIONS, AND PROGRAMS.
Integer Multiplication, Division Arithmetic shift Twice the number of places MIPS multiply unit. mult, multu Significant bits Mfhi, mflo, div, divu Arithmetic.
The Assemble, Unassemble commands of the debugger: U Command for converting machine code language source Equivalent machine code instructions Equivalent.
ECEN 248: INTRODUCTION TO DIGITAL SYSTEMS DESIGN Lecture 8 Dr. Shi Dept. of Electrical and Computer Engineering.
Chapter 1 Representing Data in a Computer. 1.1 Binary and Hexadecimal Numbers.
Chapter 8 Computer Arithmetic. 8.1 Unsigned Notation Non-negative notation  It treats every number as either zero or a positive value  Range: 0 to 2.
ECE 3110: Introduction to Digital Systems Signed Number Conversions and operations.
1 Integer Representations V1.0 (22/10/2005). 2 Integer Representations  Unsigned integer  Signed integer  Sign and magnitude  Complements  One’s.
Arithmetic Circuits I. 2 Iterative Combinational Circuits Like a hierachy, except functional blocks per bit.
Lecture 4: Digital Systems & Binary Numbers (4)
Unit I From Fundamentals of Logic Design by Roth and Kinney.
CHAPTER 1 INTRODUCTION NUMBER SYSTEMS AND CONVERSION
Lecture Set 5 The 8051 Instruction Set.
Data Processing Instructions
Instruction Groups The 8051 has 255 instructions.
Lecture 8: Addition, Multiplication & Division
Memory Organisation Source: under
The 8051 Assembly Language Arithmetic & Logic Instructions
Lecture 8: Addition, Multiplication & Division
Microprocessor and Assembly Language
2’s Complement form 1’s complement form 2’s complement form
Number Systems Rayat Shikshan Sanstha’s
Number Systems Rayat Shikshan Sanstha’s
Chapter 5 Arithmetic and Logic Instructions
ECE 331 – Digital System Design
ARITHMETIC, LOGIC INSTRUCTIONS, AND PROGRAMS
COMS 361 Computer Organization
Chapter 1 (Part c) Digital Systems and Binary Numbers
Presentation transcript:

Arithmetic Instructions and Programs

Outlines Range of numbers in 8051 unsigned data Range of numbers in 8051 unsigned data Addition & subtraction instructions for unsigned data Addition & subtraction instructions for unsigned data BCD system of data representation BCD system of data representation Packed and unpacked BCD data Packed and unpacked BCD data Addition & subtraction on BCD data Addition & subtraction on BCD data Range of numbers in 8051 signed data Range of numbers in 8051 signed data Signed data arithmetic instructions Signed data arithmetic instructions Carry & overflow problems & corrections Carry & overflow problems & corrections

Addition of Unsigned Numbers ADDA, source; A = A + source ADDA, source; A = A + source

Addition of Individual Bytes

ADDC & Addition of 16-bit Numbers 1 3CE7 3B8D

BCD Number System Unpacked BCD: 1 byte Unpacked BCD: 1 byte Packed BCD: 4 bits Packed BCD: 4 bits

Adding BCD Numbers & DA Instruction MOVA,#17H ADDA,#28H MOVA,#47H;A=47H first BCD operandMOVB,#25H;B=25 second BCD operand ADDA,B;hex (binary) addition (A=6CH) DAA;adjust for BCD addition (A=72H) HEXBCD AC=

Example

Subtraction of Unsigned Numbers SUBBA, source; A = A – source – CY SUBBA, source; A = A – source – CY SUBB when CY = 0 SUBB when CY = 0 Take 2 ’ s complement of subtraend (source)Take 2 ’ s complement of subtraend (source) Add it to minuendAdd it to minuend Invert carryInvert carry

Example (Positive Result)

Example (Negative Result)

SUBB When CY = 1 For multibyte numbers For multibyte numbers

Multiplication of Unsigned Numbers MULAB; A  B, place 16-bit result in B and A MULAB; A  B, place 16-bit result in B and A MOVA,#25H;load 25H to reg. A MOVB,#65H;load 65H in reg. B MULAB;25H * 65H = E99 where ;B = 0EH and A = 99H Table 6-1:Unsigned Multiplication Summary (MUL AB) Multiplication Operand 1 Operand 2 Result byte  byte AB A=low byte, B=high byte

Division of Unsigned Numbers DIVAB; divide A by B DIVAB; divide A by B MOVA,#95H;load 95 into A MOVB,#10H;load 10 into B DIVAB;now A = 09 (quotient) and ;B = 05 (remainder) Table 6-2:Unsigned Division Summary (DIV AB) DivisionNumerator Denominat or Quotient Remainde r byte / byte ABAB

Example ( 1 of 2 )

Example ( 2 of 2 )

Signed 8-bit Operands Covert to 2 ’ s complement Covert to 2 ’ s complement Write magnitude of number in 8-bit binary (no sign)Write magnitude of number in 8-bit binary (no sign) Invert each bitInvert each bit Add 1 to itAdd 1 to it

Example

Example

Example

Byte-sized Signed Numbers Ranges DecimalBinaryHex …. ………… FE FF …………… F

Overflow in Signed Number Operations

When Is the OV Flag Set? Either: there is a carry from D6 to D7 but no carry out of D7 (CY = 0) Either: there is a carry from D6 to D7 but no carry out of D7 (CY = 0) Or: there is a carry from D7 out (CY = 1) but no carry from D6 to D7 Or: there is a carry from D7 out (CY = 1) but no carry from D6 to D7

Example

Example

Example