Arithmetic and Logic Instructions

Slides:



Advertisements
Similar presentations
Copyright ©2009 by Pearson Education, Inc. Upper Saddle River, New Jersey All rights reserved. The Intel Microprocessors: 8086/8088, 80186/80188,
Advertisements

Microprocessors.
Introduction to Computer Engineering by Richard E. Haskell BCD Arithmetic Module M16.5 Section 10.4.
1 x86’s instruction sets. 2 Instruction Set Classification  Transfer Move  Arithmetic Add / Subtract Mul / Div, etc.  Control Jump Call / Return, etc.
Department of Computer Science and Software Engineering
ACOE2511 Assembly Language Arithmetic and Logic Instructions.
Web siteWeb site ExamplesExamples Irvine, Kip R. Assembly Language for Intel-Based Computers, MUL Instruction The MUL (unsigned multiply) instruction.
Gursharan Singh Tatla 21-Nov-20101www.eazynotes.com.
8086 : INSTRUCTION SET By, Pramod Sunagar Assistant Professor
© 2006 Pearson Education, Upper Saddle River, NJ All Rights Reserved.Brey: The Intel Microprocessors, 7e Chapter 5 Arithmetic and Logic Instructions.
9-1 ECE 424 Design of Microprocessor-Based Systems Haibo Wang ECE Department Southern Illinois University Carbondale, IL x86 Instructions Part.
Shift and Rotate Instructions
Dr Masri Ayob TK 2633: Microprocessor & Interfacing Lecture 5: Arithmetic and Logic Instructions.
Chapter 4 Basic Instructions. 4.1 Copying Data mov Instructions mov (“move”) instructions are really copy instructions, like simple assignment statements.
Unit-1 PREPARED BY: PROF. HARISH I RATHOD COMPUTER ENGINEERING DEPARTMENT GUJARAT POWER ENGINEERING & RESEARCH INSTITUTE Advance Processor.
CE302 Outline Multiplication Division Program Segment Prefix Command Line Parameters.
MUL Instruction (Unsigned Multiply) Multiplies an 8-, 16-, or 32-bit operand by either AL, AX or EAX. MUL r/m8 MUL r/m16 MUL r/m32.
Lecture – 5 Assembly Language Programming
The M68HC11 Basic Instruction Set Basic Arithmetic Instructions
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.
Flag Control instructions CLC clear carry flag CF = 0 STC set carry flag CF= 1 CMC complement carry flag [CF] CF.
9/20/6Lecture 3 - Instruction Set - Al Instruction Set (2)
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.
Lecture – 4 PIC18 Family Instruction Set 1. Outline Literal instructions. Bit-oriented instructions. Byte-oriented instructions. Program control instructions.
Microprocessors Monday, Apr. 13 Dr. Asmaa Farouk Faculty of Engineering, Electrical Department, Assiut University.
Copyright 2000ELEC 242 Arithmetic Instructions1 Arithmetic Instructions Arithmetic and logical instructions modify the contents of the Flag (Status) register.
Arithmetic Flags and Instructions
Computer Architecture and Operating Systems CS 3230 :Assembly Section Lecture 4 Department of Computer Science and Software Engineering University of Wisconsin-Platteville.
1 IKI10230 Pengantar Organisasi Komputer Kuliah no. 05.b: Arithmetic Operations Sumber: 1. Paul Carter, PC Assembly Language 2. Hamacher. Computer Organization,
Ass. Prof. Dr Masri Ayob Lecture 5: Arithmetic and Logic Instructions TK 2633: Microprocessor & Interfacing.
1 Logic, Shift, and Rotate Instructions Read Sections 6.2, 7.2 and 7.3 of textbook.
Logical and Bit Operations Chapter 9 S. Dandamudi.
3.4 Addressing modes Specify the operand to be used. To generate an address, a segment register is used also. Immediate addressing: the operand is a number.
Chapter 7: Integer Arithmetic. 2 Chapter Overview Shift and Rotate Instructions Shift and Rotate Applications Multiplication and Division Instructions.
The Assemble, Unassemble commands of the debugger: U Command for converting machine code language source Equivalent machine code instructions Equivalent.
Introduction Arithmetic instructions are used to perform arithmetic operation such as Addition Subtraction Multiplication Division These operations can.
Chapter 7 Bit Manipulation. 7.1 Logical Operations.
Microprocessor & Assembly Language Arithmetic and logical Instructions.
Microprocessor & Assembly Language
Computer and Information Sciences College / Computer Science Department CS 206 D Computer Organization and Assembly Language.
Riyadh Philanthropic Society For Science Prince Sultan College For Woman Dept. of Computer & Information Sciences CS 251 Introduction to Computer Organization.
Multiplication and Division instructions Dr.Hadi AL Saadi.
The Microprocessor & Its Architecture A Course in Microprocessor Electrical Engineering Department Universitas 17 Agustus 1945 Jakarta.
Data Transfers, Addressing, and Arithmetic
EE3541 Introduction to Microprocessors
Multiplication and Division Instructions
INSTRUCTION SET.
4.2 Arithmetic Instructions
INSTRUCTION SET OF 8086 PAWAN KUMAR SINGH.
CS 301 Fall 2002 Assembly Instructions
X86’s instruction sets.
The 8051 Assembly Language Arithmetic & Logic Instructions
Morgan Kaufmann Publishers Computer Organization and Assembly Language
Microprocessor and Assembly Language
Shift & Rotate Instructions)
Multiplication and Division Instructions
ADDITION Register Addition. ADD AX,BX AX=AX+BX 2. Immediate Addition.
Shift & Rotate Instructions)
Arithmetic and Logic Chapter 5
Branching instructions
EECE.3170 Microprocessor Systems Design I
Chapter 5 Arithmetic and Logic Instructions
Data Movement Instructions
Chapter 5: Arithmetic and Logic Instructions
Multiplication and Division Instructions
Multiplication and Division Instructions
Presentation transcript:

Arithmetic and Logic Instructions A Course in Microprocessor Electrical Engineering Department University of Indonesia

Addition-Subtraction-Comparison Whenever arithmetic and logic instruction execute, the contents of the flag register change Addition Table 5.1 illustrates the addressing modes available to the ADD instructions Register Addition Example 5.1 show a sample of register addition Immediate Addition Example 5.2 shows 8-bit immediate addition example

Addition-Subtraction-Comparison (cont’d) Memory-to-Register Addition Example 5.3 adds two consecutive bytes of data Array Addition Example 5.4 shows a procedure that adds the contents of array elements 3, 5, and 7 Example 5.5 shows the scaled-index form of addressing to add elements 3, 5, and 7 of an area of memory called ARRAY Increment Addition Examples 5.6 modifies example 5.3 to use the increment instruction for addressing NUMB and NUMB+1 (see also Table 5.2)

Addition-Subtraction-Comparison (cont’d) Addition-with-Carry Table 5.3 lists several add-with-carry instruction Figure 5.1 illustrates the addition Ex. 5.7 and Ex. 5.8 show the short program Subtraction Table 5.4 shows addressing modes for the subtraction instruction Register Subtraction Example 5.9 Immediate Subtraction Example 5.10

Addition-Subtraction-Comparison (cont’d) Decrement Subtraction It subtracs a 1 from a register or the contents of a memory location (see Table 5.5) Subtract-with-Borrow It functions as a regular subtraction, except that the carry flag (C) which holds the borrow, also subtracts from the difference (see Table 5.6 & Ex. 5.11) Comparison The comparison instruction (CMP) is a subtraction that changes only the flag bits See Table 5.7 and Example 5.12

Multiplication and Division Only modern p contain multiplication and division instructions Multiplication multiplication (bytes, words, or doublewords) can be signed integer (IMUL) or unsigned (MUL) 8-bit Multiplication The multiplicant is always in the register AL See Table 5.8 and Example 5.13 16-bit Multiplication AX contains the multiplicand and the product appears in DX-AX

Multiplication and Division (cont’d) 32-bit Muliplication The contents of EAX are multiplied by the operand specified with the instruction The product (64-bits wide) is found in EDX-EAX where EAX contains the LS32B (see Table 5.10) Division None of the flag bits change predictably; i.e., a division can result is two different types of error: an attempt to divide by zero a divide overflow (see the 3rd paragraph in p.157) In both cases, the p generates an interrupt if a divide error occurs

Multiplication and Division (cont’d) 8-bit Division The AX register stores the dividend After the division, AL contains the quotient and AH contains a whole number remainder See Table 5.11, Example 5.14 & Example 5.15 16-bit Division Instead of dividing into AX, the 16-bit number is divided into DX-AX, a 32-bit dividend The qutient appears in AX and the remainder in DX after a 16-bit division See Table 5.12 and Example 5.16

Multiplication and Division (cont’d) 32-bit Division The 64-bit contents of EDX-EAX are divided by the operand specified by the instruction, leaving a 32-bit quotient in EAX and a 32-bit remainder in EDX See Table 5.13 The Remainder After a division, the remainder could be use to round the result or dropped to truncate the result or conver-ted to a fractional remainder Study Example 5.17 and Example 5.18

BCD and ASCII Arithmetic BCD Arithmetic p allows arithmetic manipulation of both BCD and ASCII DAA (Decimal Adjust After Addition) Instruction It follows the ADD or ADC instruction to adjust the result into a BCD result (Ex. 5.19) DAS (Decimal Adjust After Subtraction) Instruction It functions as does the DAA, except that it follows a subtraction instead of an addition (Ex. 5.20)

BCD and ASCII Arithmetic (cont’d) AAA (ASCII Adjust After Addition) Example 5.21 AAD (ASCII Adjust Before Division) Example 5.22 AAM (ASCII Adjust After Multiplication) Example 5.23, Example 5.24, Example 5.25 AAS (ASCII Adjust After Subtraction) Adjust the AX register after an ASCII subtraction

Basic Logic Instruction Logic operations provide binary bit control in low-level software; allow bits to be set, cleared, or complemented AND Performs logical multiplication as depicted by the truth table in Fig.5.3 and Fig. 5.4 See also Ex. 5.26 and Table 5.14 OR Performs logical addition as depicted in Fig. 5.5 and Ex. 5.27 and Fig. 5.6 and Table 5.15 X-OR Study Fig. 5.7, Table 5.16 and Ex 5.28

Basic Logic Instruction (cont’d) Test and Bit Test Instruction Test instruction performs the AND operation; the differece is that the AND instruction changes the destination operand, while the TEST does not Test instruction affects only the flag (Table 5.17 and Example 5.29) Bit Test instruction tests single bit position (Table 5.18 and Example 5.30 NOT and NEG NOT performs logical inversion (1’s complement) and NEG performs arithmetic sign inversion (2’s complement)

Shift and Rotate Shifts Shift and Rotate instructions manipulate binary numbers at the binary bit level Shifts and Rotates find their most common application in low-level software used to control I/O devices Shifts Shifts position or move numbers to the left or right within a register or memory location Shifts also perform simple arithmetic such as multiplication by powers of 2+n (left shift) and division by powers of 2-n (right shift) Study fig. 5.9, Table 5.20, Examples 5.31 & 5.32

Shift and Rotate (cont’d) Rotates position binary data by rotating the infromation in a register or memory location either from one end to another or through the carry flag Rotates are often used to shift wide numbers to the left or right Study Fig. 5.10, Table 5.21, Example 5.33 Bit Scan Instructions BSF (bit scan forward) and BSR (bit scan reverse) scan through a number searching for the first 1-bit encountered

String Comparisons SCAS CMPS It is very powerful because allows to manipulate large blocks of data with relative ease SCAS SCAS compares the AL register with a byte block of memory (SCASB), the AX register with a word block of memory (SCASW), or the EAX register with a doubleword block of memory (SCASD) study Example 5.34 and Example 5.35 CMPS It always compares two sections of memory data as bytes (CMPSB), word (CMPSW), or doubleword (CMPSD); Study Example 5.36