The 8051 Microcontroller and Embedded Systems

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

The 8051 Microcontroller and Embedded Systems
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)
Msc. Ivan A. Escobar Broitman Microprocessors 1 1 The 8051 Instruction Set.
ARITHMETIC, LOGIC INSTRUCTIONS, AND PROGRAMS
Princess Sumaya Univ. Computer Engineering Dept. Chapter 3:
Princess Sumaya Univ. Computer Engineering Dept. Chapter 3: IT Students.
Digital Fundamentals Floyd Chapter 2 Tenth Edition
Assembly Language and Computer Architecture Using C++ and Java
© 2006 Pearson Education, Upper Saddle River, NJ All Rights Reserved.Brey: The Intel Microprocessors, 7e Chapter 5 Arithmetic and Logic Instructions.
Dr Masri Ayob TK 2633: Microprocessor & Interfacing Lecture 5: Arithmetic and Logic Instructions.
CSCE 211: Digital Logic Design Chin-Tser Huang University of South Carolina.
VIT UNIVERSITY1 ECE 103 DIGITAL LOGIC DESIGN CHAPTER I NUMBER SYSTEMS AND CODES Reference: M. Morris Mano & Michael D. Ciletti, "Digital Design", Fourth.
DIGITAL SYSTEMS TCE1111 Representation and Arithmetic Operations with Signed Numbers Week 6 and 7 (Lecture 1 of 2)
Microcontroller Intel 8051
1.6 Signed Binary Numbers.
MICROCONTROLLER INSTRUCTION SET
The M68HC11 Basic Instruction Set Basic Arithmetic Instructions
© 2009 Pearson Education, Upper Saddle River, NJ All Rights ReservedFloyd, Digital Fundamentals, 10 th ed Digital Fundamentals Tenth Edition Floyd.
Programmable Logic Controllers
Simple Data Type Representation and conversion of numbers
Number Systems Part 2 Numerical Overflow Right and Left Shifts Storage Methods Subtraction Ranges.
CoE3DJ4 Digital Systems Design Chapter 3: instruction set summary.
Khaled A. Al-Utaibi  Introduction  Arithmetic Instructions  Basic Logical Instructions  Shift Instructions  Rotate Instructions.
CHAPTER 1 INTRODUCTION NUMBER SYSTEMS AND CONVERSION.
The 8051 Microcontroller and Embedded Systems
CHAPTER 1 INTRODUCTION NUMBER SYSTEMS AND CONVERSION
Number Systems ELEC 311 Digital Logic and Circuits Dr. Ron Hayne Images Courtesy of Cengage Learning.
ASCII and BCD Arithmetic Chapter 11 S. Dandamudi.
Embedded System Spring, 2011 Lecture 10: Arithmetic, Logic Instruction and Programs Eng. Wazen M. Shbair.
University Of Engineering And Technology Taxila REF::NATIONAL TAIWANOCEAN UNIVERSITY 國立台灣海洋大學 Chapter 3 JUMP, LOOP and CALL Instructions.
Princess Sumaya Univ. Computer Engineering Dept. Chapter 3:
The 8051 Microcontroller and Embedded Systems
ACOE2511 Assembly Language for the 80X86/Pentium Intel Microprocessors Lecturer: Dr. Konstantinos Tatas.
Computer Math CPS120 Introduction to Computer Science Lecture 4.
COMPUTER ORGANISATION Sri.S.A.Hariprasad Sr.Lecturer R.V.C.E Bangalore.
IT1004: Data Representation and Organization Negative number representation.
CHAPTER 6 ARITHMETIC, LOGIC INSTRUCTIONS, AND PROGRAMS.
Arithmetic and Logic Chapter 5
ECE DIGITAL LOGIC LECTURE 3: DIGITAL COMPUTER AND NUMBER SYSTEMS Assistant Prof. Fareena Saqib Florida Institute of Technology Fall 2016, 01/19/2016.
Instruction Sets. Instruction set It is a list of all instructions that a processor can execute. It is a list of all instructions that a processor can.
Microprocessor & Assembly Language Arithmetic and logical Instructions.
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.
Number Systems. The position of each digit in a weighted number system is assigned a weight based on the base or radix of the system. The radix of decimal.
Arithmetic Instructions and Programs. Outlines Range of numbers in 8051 unsigned data Range of numbers in 8051 unsigned data Addition & subtraction instructions.
Classification of Instruction Set of 8051
CHAPTER 1 INTRODUCTION NUMBER SYSTEMS AND CONVERSION
Microprocessor Systems Design I
The 8051 Microcontroller and Embedded Systems
Lecture Set 5 The 8051 Instruction Set.
TAO1221 COMPUTER ARCHITECTURE AND ORGANIZATION LAB 6
Data Processing Instructions
Arithmetic and Logic Chapter 5
Instruction Groups The 8051 has 255 instructions.
INTRODUCTION TO LOGIC DESIGN Chapter 1 Digital Systems and Binary Numbers gürtaçyemişçioğlu.
Memory Organisation Source: under
The 8051 Assembly Language Arithmetic & Logic Instructions
Chapter 11 © 2011, The McGraw-Hill Companies, Inc.
Introduction to Micro Controllers & Embedded System Design Instruction set Department of Electrical & Computer Engineering Missouri University of Science.
Microprocessor and Assembly Language
Digital Logic & Design Lecture 03.
Digital Logic & Design Lecture 02.
Introduction to Micro Controllers & Embedded System Design Instruction set Department of Electrical & Computer Engineering Missouri University of Science.
DMT 245 Introduction to Microcontroller
2’s Complement form 1’s complement form 2’s complement form
Arithmetic and Logic Chapter 5
Chapter 5 Arithmetic and Logic Instructions
8051 ASSEMBLY LANGUAGE PROGRAMMING
ARITHMETIC, LOGIC INSTRUCTIONS, AND PROGRAMS
Presentation transcript:

The 8051 Microcontroller and Embedded Systems CHAPTER 6 ARITHMETIC, LOGIC INSTRUCTIONS, AND PROGRAMS

OBJECTIVES Define the range of numbers possible in 8051 unsigned data Code addition and subtraction instructions for unsigned data Perform addition of BCD data Code 8051 unsigned data multiplication and division instructions Code 8051 Assembly language logic instructions AND, OR, and EX-OR Use 8051 logic instructions for bit manipulation Use compare and jump instructions for program control Code 8051 rotate instruction and data serialization Explain the BCD (binary coded decimal) system of data representation Contrast and compare packed and unpacked BCD data Code 8051 programs for ASCII and BCD data conversion Code 8051 programs to create and test the checksum byte

Addition of unsigned numbers The form of the ADD instruction is ADD A, source ;A = A + source

Addition of individual bytes

ADDC and addition of 16-bit numbers

BCD (binary coded decimal) number system Unpacked BCD The lower 4 bits of the number represent the BCD number. The rest of the bits are 0. For example, "0000 1001" and "0000 0101" are unpacked BCD for 9 and 5, respectively. Unpacked BCD requires 1 byte of memory or an 8-bit register to contain it.

SECTION 6.1: ARITHMETIC INSTRUCTIONS Unpacked BCD Figure 6–1 BCD Code

BCD (binary coded decimal) number system Packed BCD A single byte has two BCD numbers in it, one in the lower 4 bits, and one in the upper 4 bits. For example, "0101 1001" is packed BCD for 59H. It takes only 1 byte of memory to store the packed BCD operands. Its more efficient than unpacked BCD.

BCD (binary coded decimal) number system There is a problem with adding BCD numbers. Adding two BCD numbers must give a BCD result. After adding packed BCD numbers, the result is no longer BCD. MOV A, #17BCD ADD A,#28BCD ;A = 3F which is not BCD ;should be 17 + 28 = 45BCD "DA A" is designed to correct the BCD addition problem.

BCD (binary coded decimal) number system DA instruction MOV A,#47H ;A=47H first BCD operand MOV B,#25H ;B=25 second BCD operand ADD A,B ;hex (binary) addition (A=6CH) DA A ;adjust for BCD addition (A=72H) DA A must be used after the addition of BCD operands. Important to note that DA A works only after an ADD instruction, it will not work after the INC instruction.

Subtraction of unsigned numbers SUBB A, source ;A = A - source – CY In the 8051 we have only have subtract with borrow SUBB. There are two cases for the SUBB instruction: (1) with CY = 0 (2) with CY = l

Subtraction of unsigned numbers

Subtraction of unsigned numbers If the CY = 0 after the execution of SUBB, the result is positive. If CY = 1, the result is negative and the destination has the 2's complement of the result. Normally, the result is left in 2's complement, but the CPL (complement) and INC instructions can be used to change it. The CPL instruction performs the 1's complement of the operand; then the operand is incremented (INC) to get the 2's complement.

Subtraction of unsigned numbers SUBB (subtract with borrow) when CY = 1

UNSIGNED MULTIPLICATION AND DIVISION In multiplying or dividing two numbers in the 8051, the use of registers A and B is required. The multiplication and division instructions work only with these two registers.

Multiplication of unsigned numbers The 8051 supports byte-by-byte multiplication only. The bytes are assumed to be unsigned data. MUL AB ;A x B, place 16-bit result in B and A After multiplication, the result is in the A and B registers. The lower byte is in A, and the upper byte is in B. MOV A,#25H ;load 25H to reg. A MOV B,#65H ;load 65H in reg. B MUL AB ;25H * 65H = E99 where ;B = 0EH and A = 99H

Multiplication of unsigned numbers Table 6–1 Unsigned Multiplication Summary (MUL AB)

Division of unsigned numbers In the division of unsigned numbers, the 8051 supports byte over byte only. DIV AB ;divide A by B The numerator must be in register A and the denominator must be in B. After the DIV instruction is performed, the quotient is in A and the remainder is in B.

Division of unsigned numbers MOV A,#95 ;load 95 into A MOV B,#10 ;load 10 into B DIV AB ;now A = 09 (quotient) and ;B = 05 (remainder) This instruction always makes CY = 0 and OV = 0 if the denominator is not 0. If the denominator is 0 (B = 0), OV = 1 indicates an error, and CY = 0. The standard practice in all microprocessors when dividing a number by 0 is to indicate in some way the invalid result of infinity. In the 805 I, the OV flag is set to 1.

Division of unsigned numbers Table 6–2 Unsigned Division Summary (DIV AB)

SECTION 6.2: SIGNED NUMBER CONCEPTS AND ARITHMETIC OPERATIONS Concept of signed numbers in computers Computers must be able to accommodate sign numbers. Computer scientists have devised the following arrangement for the representation of signed positive and negative numbers: The most significant bit (MSB) is set aside for the sign (+ or -), while the rest of the bits are used for the magnitude. The sign is represented by 0 for positive (+) numbers and 1 for negative (- ) numbers.

Signed 8-bit operands In signed byte operands, D7 (MSB) is the sign and D0 to D6 are set aside for the magnitude of the number. If D7 = 0, the operand is positive, and if D7 = 1, it is negative.

Positive numbers The range of positive numbers that can be represented is 0 to +127. If a positive number is larger than +127, a 16-bit size operand must be used.

Negative numbers For negative numbers, D7 is1. The magnitude is represented in its 2's complement. To convert to negative number representation (2's complement): 1. Write the magnitude of the number in 8-bit binary (no sign). 2. Invert each bit. 3. Add 1 to it.

Overflow problem in signed number operations When using signed numbers, a serious problem arises that must be dealt with. This is the overflow problem. The 8051 indicates the existence of an error by raising the OV (overflow) flag. If the result of an operation on signed numbers is too large for the register, an overflow has occurred and the programmer must be notified.

Compare instruction CJNE destination,source,relative address

SECTION 6.3: LOGIC AND COMPARE INSTRUCTIONS Table 6–3 Carry Flag Setting For CJNE Instruction

SECTION 6.4: ROTATE INSTRUCTION AND DATA SERIALIZATION Rotating through the carry In the 8051 the rotation instructions RL, RR, RLC, and RRC are designed to rotate the accumulator right or left. To rotate a byte the operand must be in register A. There are two type of rotations. One is a simple rotation of the bits of A, and the other is a rotation through the carry.

Serializing data Serializing data is a way of sending a byte of data one bit at a time through a single pin of microcontroller. There are two ways to transfer a byte of data serially: 1. Using the serial port. The details of serial port data transfer are discussed in Chapter 10. 2. The second method of serializing data is to transfer data one bit at a time and control the sequence of data and spaces in between them. In many new devices such as LCD, ADC, and ROM, the serial versions of these devices are becoming popular since they take less space on a printed circuit board.

Serializing a byte of data

Single-bit operations with CY Table 6–4 Carry Bit-Related Instructions

ASCII numbers Table 6–5 ASCII Code for Digits 0–9

Checksum byte in ROM To ensure the integrity of the ROM contents, every system must perform the checksum calculation. The process of checksum will detect any corruption of the contents of ROM. The checksum byte is an extra byte that is tagged to the end of a series of bytes of data. To calculate the checksum byte of a series of bytes of data, the following steps can be taken: 1. Add the bytes together and drop the carries. 2. Take the 2's complement of the total sum; this is the checksum byte, which becomes the last byte of the series.

Checksum byte in ROM To perform the checksum operation, add all the bytes, including the check­sum byte. The result must be zero. If it is not zero, one or more bytes of data have been changed (corrupted).

Next … Lecture Problems Textbook Chapter 6 Proteus Exercise 6 Answer as many questions as you can and submit via MeL before the end of the lecture. Proteus Exercise 6 Do as much of the Proteus exercise as you can and submit via MeL before the end of the lecture.