Copyright 2000ELEC 242 Arithmetic Instructions1 Arithmetic Instructions Arithmetic and logical instructions modify the contents of the Flag (Status) register.

Slides:



Advertisements
Similar presentations
1 x86’s instruction sets. 2 Instruction Set Classification  Transfer Move  Arithmetic Add / Subtract Mul / Div, etc.  Control Jump Call / Return, etc.
Advertisements

Department of Computer Science and Software Engineering
ACOE2511 Assembly Language Arithmetic and Logic Instructions.
Computer Organization & Assembly Language
80x86 Instruction Set Dr. Qiang Lin.
Web siteWeb site ExamplesExamples Irvine, Kip R. Assembly Language for Intel-Based Computers, MUL Instruction The MUL (unsigned multiply) instruction.
8086 : INSTRUCTION SET By, Pramod Sunagar Assistant Professor
9-1 ECE 424 Design of Microprocessor-Based Systems Haibo Wang ECE Department Southern Illinois University Carbondale, IL x86 Instructions Part.
CS2422 Assembly Language & System Programming September 28, 2006.
Shift and Rotate Instructions
Chapter 4 Basic Instructions. 4.1 Copying Data mov Instructions mov (“move”) instructions are really copy instructions, like simple assignment statements.
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.
Ch. 7 Logic, Shift and Rotate instr.
Khaled A. Al-Utaibi  Introduction  Arithmetic Instructions  Basic Logical Instructions  Shift Instructions  Rotate Instructions.
Sahar Mosleh California State University San MarcosPage 1 CPU Flags and Boolean Instructions.
Types of Registers (8086 Microprocessor Based)
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.
ICS312 Set 9 Logic & Shift Instructions. Logic & Shift Instructions Logic and Shift Instructions can be used to change the bit values in an operand. The.
Microprocessors Monday, Apr. 13 Dr. Asmaa Farouk Faculty of Engineering, Electrical Department, Assiut University.
Boolean and Comparison Instructions Operation Description ANDAND Destination, Source OROR Destination, Source XORXOR Destination, Source NOTNOT Destination.
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,
1 Logic, Shift, and Rotate Instructions Read Sections 6.2, 7.2 and 7.3 of textbook.
Assembly Language. Symbol Table Variables.DATA var DW 0 sum DD 0 array TIMES 10 DW 0 message DB ’ Welcome ’,0 char1 DB ? Symbol Table Name Offset var.
Logical and Bit Operations Chapter 9 S. Dandamudi.
Review of Assembly language. Recalling main concepts.
October 1, 2003Serguei A. Mokhov, 1 SOEN228, Winter 2003 Revision 1.2 Date: October 25, 2003.
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.
Microprocessor MA Rahim Khan Computer Engineering and Networks Department.
Arithmetic Flags and Instructions Chapter 7 S. Dandamudi.
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.
Comparison Instructions Test instruction –Performs an implied AND operation between each of the bits in 2 operands. Neither operand is modified. (Flags.
Internal Programming Architecture or Model
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.
Boolean, Shift and Rotate instructions Dr.Hadi AL Saadi.
K.K. Leung Fall 2008Introductory Pentium Programming1 Pentium Architecture: Introductory Programming Kin K. Leung
Multiplication and Division instructions Dr.Hadi AL Saadi.
Chapter Nov-2010
Data Transfers, Addressing, and Arithmetic
Microprocessor Systems Design I
8086 Microprocessor.
ICS312 SET 7 Flags.
The FLAGS Register An x bit means an unidentified value 9/12/2018
Assembly Language for Intel-Based Computers, 5th Edition
EE3541 Introduction to Microprocessors
Basic Assembly Language
Assembly IA-32.
INSTRUCTION SET.
More on logical instruction and
Assembly Language Programming Part 2
4.2 Arithmetic Instructions
INSTRUCTION SET OF 8086 PAWAN KUMAR SINGH.
Arithmetic Instructions
X86’s instruction sets.
Chapter 4: Instructions
Shift & Rotate Instructions)
Multiplication and Division Instructions
Shift & Rotate Instructions)
Assembly Language for Intel-Based Computers, 4th Edition
Assembly Language for Intel-Based Computers, 5th Edition
Computer Architecture CST 250
Chapter 5 Arithmetic and Logic Instructions
Microprocessor and Assembly Language
CNET 315 Microprocessor & Assembly Language
Chapter 8: Instruction Set 8086 CPU Architecture
Division instruction.
Presentation transcript:

Copyright 2000ELEC 242 Arithmetic Instructions1 Arithmetic Instructions Arithmetic and logical instructions modify the contents of the Flag (Status) register based on the operation performed and the result of the operation.

Copyright 2000ELEC 242 Arithmetic Instructions2 ADD ADD destination,source DEST <= DEST + SOURCE The operand may be immediate, a register, or memory. Both Operands must be the same size. ADD AL,BH ;AL <= AL + BH ADD [SUM],AX ;[SUM] <= [SUM] + AX ADD EAX, 5 ;EAX <= EAX H

Copyright 2000ELEC 242 Arithmetic Instructions3 ADD – Flag Modification mov al, 0FFh; AL <= AL + 0FFH add al,1; AL=00h, OF=0, CF=1 add al, 07FH; AL=80h, OF=1, CF=0 add al,80h; AL=00h, OF=1, CF=1 Therefore, we may have either type of overflow or both types of overflow at the same time

Copyright 2000ELEC 242 Arithmetic Instructions4 SUB SUB destination,source DEST <= DEST - SOURCE The operand may be immediate, a register, or memory. Both operands must be of the same size and they cannot be both mem operands Recall that to perform A - B the CPU in fact performs A + (-B) or 2’s complement addition.

Copyright 2000ELEC 242 Arithmetic Instructions5 SUB – Flag Modification affect all the status flags based on the result ZF (zero flag) = 1 iff (if and only if) the result is zero SF (sign flag) = 1 iff the msb of the result is one OF (overflow flag) = 1 iff there is a signed overflow CF (carry flag) = 1 iff there is an unsigned overflow Signed overflow: when the operation generates an out-of- range signed value Unsigned overflow: when the operation generates an out- of-range unsigned value Both types of overflow occur independently and are indicated individually by CF and OF

Copyright 2000ELEC 242 Arithmetic Instructions6 SUB Examples mov ax,2;flags not modified on mov sub ax,1;sf=0 cf=0 sub ax,1;sf=1 cf=1 sub ax,80H;sf=1 cf=0

Copyright 2000ELEC 242 Arithmetic Instructions7 INC and DEC The INC (increment) and DEC (decrement) instructions add 1 or subtract 1 from a single operand (either mem or reg operand) INC destination INCSI;SI <= SI + 1 INCDX;DX <= DX + 1 INC[COUNT];a memory location COUNT DEC destination DEC [DI] ;decrement a memory location DECCX;CX <= CX - 1 DEC[COUNT];a memory location COUNT

Copyright 2000ELEC 242 Arithmetic Instructions8 Flags for INC and DEC mov BH,0FFh; CF=0, OF=0 inc bh ; BH=00h, CF=0, OF=0 mov BH,7Fh; CF=0, OF=0 inc bh; BH=80h, CF=0, OF=1

Copyright 2000ELEC 242 Arithmetic Instructions9 Multiply Instructions The multiply instruction multiplies an 8-bit, 16- bit, or 32-bit operand in AL, AX, or EAX by a register or memory multiplier. The operand cannot be immediate. The instruction format is: mulreg mulmem

Copyright 2000ELEC 242 Arithmetic Instructions10 Multiply Format MultiplicandMultiplierResult AL8-bitAX 16-bitDX:AX EAX32-bitEDX:EAX

Copyright 2000ELEC 242 Arithmetic Instructions11 MULT Examples ;Example 1 moval,20 movbl,4 mulbl; The product is in AX ;Example 2.data val1dw2000 val2dw1000 movax,val1 mulval2; The product is in DX:AX

Copyright 2000ELEC 242 Arithmetic Instructions12 MULT Examples ; Make sure to enable 386 instruction set.data val1dw val2dw moveax,val1 mulval2 ; The product is in EDX:EAX

Copyright 2000ELEC 242 Arithmetic Instructions13 Divide Instructions The divide instruction multiplies an 8-bit, 16-bit, or 32-bit operand in, AX, or EAX by a register or memory multiplier. The operand cannot be immediate. The instruction format is: divreg divmem

Copyright 2000ELEC 242 Arithmetic Instructions14 Divide Instruction Format DividendDividerQuotientRemainder AX8-bitALAH DX:AX16-bitAXDX EDX:EAX32-bitEAXEDX

Copyright 2000ELEC 242 Arithmetic Instructions15 DIV Examples movax,21 movbl,4 divbl ; The quotient is in AL ; The remainder is in AH Example 2: Divide 2000 by 1000 using a memory operand:.data val1dw2000 val2dw1000 mov dx,0 movax,val1 divval2 ; The remainder:quotient is located in DX:AX

Copyright 2000ELEC 242 Arithmetic Instructions16 DIV Examples ;Example 3.data val1dw val2dw mov edx,0 moveax,val2 divval1 ; The remainder:quotient is in EDX:EAX

Copyright 2000ELEC 242 Arithmetic Instructions17 Compare Instruction Compare is similar to subtract The result is not retained. Only the flags are set or cleared. The syntax of the instruction is CMP DEST,SOURCE Both operands must be the same data size. Based on the results of the compare, all flags are set or cleared.

Copyright 2000ELEC 242 Arithmetic Instructions18 Compare Example Copy a character into a register See if it’s a specific character. ;Compare DS:SI contents to a tilde CMP [SI], “~”;IF memory (SI is pointer) is ~ JZFINI;THEN Jump if zero to FINI MOVDL, [SI] ;ELSE Copy memory to DL In the above code: CMP is an IF JZ is a THEN MOV is an ELSE