CHAPTER 6 ARITHMETIC, LOGIC INSTRUCTIONS, AND PROGRAMS

Similar documents
Principle and Interface Techniques of Microcontroller

ET355 Microprocessors Thursday 6:00 pm 10:20 pm


ELEG3923 Microprocessor Ch.6 Arithmetic and Logics

8051 Programming: Arithmetic and Logic

8051 Microcontrollers

Microprocessors 1. The 8051 Instruction Set. Microprocessors 1 1. Msc. Ivan A. Escobar Broitman

Microcontroller Intel [Instruction Set]

TUTORIAL Assembly Language programming (2)

8051 Overview and Instruction Set

Programming of 8085 microprocessor and 8051 micro controller Study material

ENE 334 Microprocessors

Architecture & Instruction set of 8085 Microprocessor and 8051 Micro Controller

Binary Addition. Add the binary numbers and and show the equivalent decimal addition.

Module Contents of the Module Hours COs

SN8F5000 Family Instruction Set

Arithmetic and Logic

Semester Transition Point. EE 109 Unit 11 Binary Arithmetic. Binary Arithmetic ARITHMETIC

Microcontroller. Instruction set of 8051

BINARY SYSTEM. Binary system is used in digital systems because it is:

Memory organization Programming model - Program status word - register banks - Addressing modes - instruction set Programming examples.

UNIT 2 THE 8051 INSTRUCTION SET AND PROGRAMMING

Arithmetic and Logic Instructions And Programs

EEM336 Microprocessors I. Arithmetic and Logic Instructions

DR bit RISC Microcontroller. Instructions set details ver 3.10

Chapter 3: part 3 Binary Subtraction

Assembly Language programming (2)

Q. Classify the instruction set of 8051 and list out the instructions in each type.

EE 109 Unit 6 Binary Arithmetic

8051 Microcontroller

Basic Definition INTEGER DATA. Unsigned Binary and Binary-Coded Decimal. BCD: Binary-Coded Decimal

UNIT THE 8051 INSTRUCTION SET AND PROGRAMMING

Digital Blocks Semiconductor IP

2. MACHINE REPRESENTATION OF TYPICAL ARITHMETIC DATA FORMATS (NATURAL AND INTEGER NUMBERS).

Arithmetic and Logical Operations

Lecture Topics. Announcements. Today: Integer Arithmetic (P&H ) Next: continued. Consulting hours. Introduction to Sim. Milestone #1 (due 1/26)

Digital Blocks Semiconductor IP

Dodatak. Skup instrukcija

Chapter 1. Digital Systems and Binary Numbers

Instruction Set Of 8051

Dragonchip. Instruction Set Manual

CHAPTER V NUMBER SYSTEMS AND ARITHMETIC

Digital Blocks Semiconductor IP

2.1. Unit 2. Integer Operations (Arithmetic, Overflow, Bitwise Logic, Shifting)

EEE3410 Microcontroller Applications Department of Electrical Engineering Lecture 4 The 8051 Architecture

Digital Fundamentals

Assembly Language Programming of 8085

Number System. Introduction. Decimal Numbers

10.1. Unit 10. Signed Representation Systems Binary Arithmetic

The x86 Microprocessors. Introduction. The 80x86 Microprocessors. 1.1 Assembly Language

Positional Number System

CHAPTER ASSEMBLY LANGUAGE PROGRAMMING

Assembly Language Programming of 8085

Module 2: Computer Arithmetic

Arithmetic Operations

(2) Explain the addressing mode of OR What do you mean by addressing mode? Explain diff. addressing mode for 8085 with examples.

CHW 261: Logic Design

INSTRUCTION SET OF 8085

C51 Family. Architectural Overview of the C51 Family. Summary


Kingdom of Saudi Arabia Ministry of Higher Education. Taif University. Faculty of Computers & Information Systems

Chapter 4 Arithmetic Functions

COE 202: Digital Logic Design Number Systems Part 2. Dr. Ahmad Almulhem ahmadsm AT kfupm Phone: Office:

Logic Circuits I ECE 1411 Thursday 4:45pm-7:20pm. Nathan Pihlstrom.

carry in carry 1101 carry carry

Digital Fundamentals. CHAPTER 2 Number Systems, Operations, and Codes

Microcomputers. Outline. Number Systems and Digital Logic Review

Signed number Arithmetic. Negative number is represented as

Computer Sc. & IT. Digital Logic. Computer Sciencee & Information Technology. 20 Rank under AIR 100. Postal Correspondence

CHETTINAD COLLEGE OF ENGINEERING AND TECHNOLOGY COMMUNICATION ENGINEERING REG 2008 TWO MARKS QUESTION AND ANSWERS

Programming Book Microcontroller Kit. Rev 3.0 January, Wichit Sirichote

TUTORIAL. Donal Heffernan University of Limerick May Tutorial D.Heffernan 2000,

Computer Organization

Microcontroller & Interfacing

Decimal & Binary Representation Systems. Decimal & Binary Representation Systems

Arithmetic,logic Instruction and Programs

8085 INSTRUCTION SET INSTRUCTION DETAILS

CPE 323 REVIEW DATA TYPES AND NUMBER REPRESENTATIONS IN MODERN COMPUTERS

8088/8086 Programming Integer Instructions and Computations

CPE 323 REVIEW DATA TYPES AND NUMBER REPRESENTATIONS IN MODERN COMPUTERS

ELEG3924 Microprocessor

CO Computer Architecture and Programming Languages CAPL. Lecture 9

Numbering systems. Dr Abu Arqoub

DIGITAL SYSTEM FUNDAMENTALS (ECE 421) DIGITAL ELECTRONICS FUNDAMENTAL (ECE 422) COURSE / CODE NUMBER SYSTEM

ELEG3923 Microprocessor Ch.2 Assembly Language Programming

Y51 Microcontroller. Technical Manual

MASSEY UNIVERSITY PALMERSTON NORTH CAMPUS

REGISTER TRANSFER LANGUAGE

World Inside a Computer is Binary

Disassembly of MC9S12 op codes Decimal, Hexadecimal and Binary Numbers

Disassembly of MC9S12 op codes Decimal, Hexadecimal and Binary Numbers

S3C80E5/P80E5/C80E7/P80E7 (Preliminary Spec)

MCS -51 Programmer s Guide and Instruction Set

Kinds Of Data CHAPTER 3 DATA REPRESENTATION. Numbers Are Different! Positional Number Systems. Text. Numbers. Other

PESIT Bangalore South Campus

Chapter 10 Binary Arithmetics

8086 INTERNAL ARCHITECTURE

User. Application program. Interfaces. Operating system. Hardware

94 CPU (CM8051) Incompatible Instruction ERRATA AND DATASHEET CLARIFICATION V1.0. Leader of Microcontroller Technology A Fabless Semiconductor Company

3.1 DATA MOVEMENT INSTRUCTIONS 45

Transcription:

CHAPTER 6 ARITHMETIC, LOGIC INSTRUCTIONS, AND PROGRAMS

Addition of Unsigned Numbers The instruction ADD is used to add two operands Destination operand is always in register A Source operand can be a register, immediate data, or in memory Memory-to-memory arithmetic operations are never allowed in 8051 Assembly language

ADDC and Addition of 16-Bit Numbers When adding two 16-bit data operands, the propagation of a carry from lower byte to higher byte is concerned

BCD Number System The binary representation of the digits 0 to 9 is called BCD (Binary Coded Decimal) Unpacked BCD The lower 4 bits of the number represent the BCD number, and the rest of the bits are 0 Ex. 00001001 and 00000101 are unpacked BCD for 9 and 5 Packed BCD A single byte has two BCD number in it, one in the lower 4 bits, and one in the upper 4 bits Ex. 0101 1001 is packed BCD for 59

BCD Number System (cont.) Adding two BCD numbers must give a BCD result

DA Instruction The DA instruction is provided to correct the aforementioned problem associated with BCD addition

DA Instruction (cont.) After an ADD or ADDC instruction If the lower nibble (4 bits) is greater than 9, or if AC=1, add 0110 to the lower 4 bits If the upper nibble is greater than 9, or if CY=1, add 0110 to the upper 4 bits

Subtraction of Unsigned Numbers In many microprocessor, there are two different instructions for subtraction: SUB and SUBB (subtract with borrow) In the 8051 we have only SUBB The 8051 uses adder circuitry to perform the subtraction To make SUB out of SUBB, we have to make CY=0 prior to the execution Notice that we use the CY flag for the borrow

Subtraction of Unsigned Numbers (cont.) SUBB when CY = 0 Take the 2 s complement of the subtrahend Add it to the minuend (A) Invert the carry CY=0, the result is positive CY=1, the result is negative The destination has the 2 s complement of the result SUBB when CY = 1 Used for multi-byte numbers Take care of the borrow of the lower operand

Unsigned Multiplication The 8051 supports byte by byte multiplication only The byte are assumed to be unsigned data

Unsigned Division The 8051 supports byte over byte division only The byte are assumed to be unsigned data

Signed 8-bit Operands D7 (MSB) is the sign and D0 to D6 are the magnitude of the number If D7=0, the operand is positive If D7=1, it is negative Positive numbers are 0 to +127

Signed 8-bit Operands D7 (MSB) is the sign and D0 to D6 are the magnitude of the number If D7=0, the operand is positive If D7=1, it is negative Positive numbers are 0 to +127

Signed 8-bit Operands (cont.) Negative number representation (2 s complement) Write the magnitude of the number in 8-bit binary (no sign) Invert each bit Add 1 to it

Overflow Problem If the result of an operation on signed numbers is too large for the register An overflow has occurred

OV Flag In 8-bit signed number operations, OV is set to 1 if either occurs: There is a carry from D6 to D7, but no carry out of D7 (CY=0) There is a carry from D7 out (CY=1), but no carry from D6 to D7

OV Flag (cont.) In unsigned number addition, we must monitor the status of CY (carry) Use JNC or JC instructions In signed number addition, the OV (overflow) flag must be monitored JB PSW.2 or JNB PSW.2 To make the 2 s complement of a number

Logic & Compare Instructions This instruction will perform a logic AND on the two operands and place the result in the destination The destination is normally the accumulator The source operand can be a register, in memory, or immediate

Logic & Compare Instructions (cont.) The destination and source operands are ORed and the result is placed in the destination The destination is normally the accumulator The source operand can be a register, in memory, or immediate

Logic & Compare Instructions (cont.) This instruction will perform XOR operation on the two operands and place the result in the destination The destination is normally the accumulator The source operand can be a register, in memory, or immediate

Logic & Compare Instructions (cont.) This is called 1 s complement To get the 2 s complement, all we have to do is to to add 1 to the 1 s complement

Compare Instruction Combining the actions of comparing and jumping into a single instruction Called CJNE (compare and jump if not equal) This instruction compares two operands, and jumps if they are not equal The destination operand can be in the accumulator or in one of the Rn registers The source operand can be in a register, in memory, or immediate

Compare Instruction (cont.) The operands themselves remain unchanged It changes the CY flag to indicate if the destination operand is larger or smaller In the CJNE instruction that any Rn register can be compared with an immediate value There is no need for register A to be involved

Compare Instruction (cont.) The compare instruction is really a subtraction Except that the operands remain unchanged Flags are changed according to the execution of the SUBB instruction

Rotating Right and Left In rotate right, the 8 bits of the accumulator are rotated right one bit Bit D0 exits from the LSB and enters into MSB, D7

Rotating Right and Left (cont.) In rotate left, the 8 bits of the accumulator are rotated left one bit, Bit D7 exits from the MSB and enters into LSB, D0

Notice in the RR and RL instructions that no flags are affected.

Rotating through Carry In RRC A, bits are rotated from left to right They exit the LSB to the carry flag, and the carry flag enters the MSB

Rotating through Carry (cont.) In RLC A, bits are shifted from right to left They exit the MSB and enter the carry flag, and the carry flag enters the LSB

Serializing Data Serializing data is a way of sending a byte of data one bit at a time through a single pin of microcontroller Using the serial port Controlling the sequence of data and spaces in between them Transfer a byte of data serially by Moving CY to any pin of ports P0 P3 Using rotate instruction

Single-bit Operations with CY There are several instructions by which the CY flag can be manipulated directly

SWAP It swaps the lower nibble and the higher nibble The lower 4 bits are put into the higher 4 bits and the higher 4 bits are put into the lower 4 bits SWAP works only on the accumulator (A)

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 process uses what is called a checksum byte The checksum byte is an extra byte that is tagged to the end of series of bytes of data

Checksum Byte in ROM (cont.) To calculate the checksum byte of a series of bytes of data Add the bytes together and drop the carries Take the 2 s complement of the total sum, and it becomes the last byte of the series To perform the checksum operation, add all the bytes, including the checksum byte The result must be zero If it is not zero, one or more bytes of data have been changed

Packed BCD to ACSII Conversion The DS5000T microcontrollers have a real-time clock (RTC) The RTC provides the time of day (hour, minute, second) and the date (year, month, day) continuously, Regardless of whether the power is on or off This data is provided in packed BCD To be displayed on an LCD or printed by the printer, it must be in ACSII format

ASCII to Packed BCD Conversion To convert ASCII to packed BCD It is first converted to unpacked BCD (to get rid of the 3) Combined to make packed BCD