Introduction Arithmetic instructions are used to perform arithmetic operation such as Addition Subtraction Multiplication Division These operations can.

Slides:



Advertisements
Similar presentations
Introduction to Computer Engineering by Richard E. Haskell BCD Arithmetic Module M16.5 Section 10.4.
Advertisements

Introduction to Computer Engineering by Richard E. Haskell Multiplication and Division Instructions Module M16.4 Section 10.4.
NEG Instruction Change operand content into two’s complement (negative value) and stored back into its operand mov bl, b neg bl; bl = mov.
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.
Assembly Language Lecture 9
1 Multiplication, Division, and Numerical Conversions Chapter 6.
Web siteWeb site ExamplesExamples Irvine, Kip R. Assembly Language for Intel-Based Computers, MUL Instruction The MUL (unsigned multiply) instruction.
1 Lecture 7 Integer Arithmetic Assembly Language for Intel-Based Computers, 4th edition Kip R. Irvine.
8086 : INSTRUCTION SET By, Pramod Sunagar Assistant Professor
CHAPTER 7 ASSEMBLY LANGUAGE INSTRUCTIONS
© 2006 Pearson Education, Upper Saddle River, NJ All Rights Reserved.Brey: The Intel Microprocessors, 7e Chapter 5 Arithmetic and Logic Instructions.
Assembly Language for Intel-Based Computers, 5 th Edition Chapter 7: Integer Arithmetic (c) Pearson Education, All rights reserved. You may.
Shift and Rotate Instructions
Chapter 2 Summary. Overview Numbers –Decimal, Binary, Octal, Hexadecimal –Their relationship Sign-magnitude One’s complement Two’s complement Arithmetic.
Chapter 4 Basic Instructions. 4.1 Copying Data mov Instructions mov (“move”) instructions are really copy instructions, like simple assignment statements.
Assembly Language for Intel-Based Computers
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.
Assembly Language – Lab 5
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.
Types of Registers (8086 Microprocessor Based)
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.
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,
Integer Arithmetic Computer Organization and Assembly Languages Yung-Yu Chuang 2007/12/24 with slides by Kip Irvine.
Arithmetic and Logic Instructions
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.
Arithmetic Flags and Instructions Chapter 7 S. Dandamudi.
Irvine, Kip R. Assembly Language for Intel-Based Computers. Chapter 7: Integer Arithmetic Slides to Accompany Assembly Language for Intel-Based Computers,
The Assemble, Unassemble commands of the debugger: U Command for converting machine code language source Equivalent machine code instructions Equivalent.
Microprocessor & Assembly Language Arithmetic and logical Instructions.
Internal Programming Architecture or Model
Multiplication and Division instructions Dr.Hadi AL Saadi.
Data Transfers, Addressing, and Arithmetic
Assembly Language for Intel-Based Computers, 5th Edition
Introduction to 8086 Microprocessor
8086 Microprocessor.
Microprocessor Systems Design I
Multiplication and Division Instructions
Assembly Language Programming Part 2
4.2 Arithmetic Instructions
INSTRUCTION SET OF 8086 PAWAN KUMAR SINGH.
X86’s instruction sets.
Introduction to Assembly Language
Chapter 4: Instructions
BIC 10503: COMPUTER ARCHITECTURE
Morgan Kaufmann Publishers Computer Organization and Assembly Language
Microprocessor and Assembly Language
Multiplication and Division Instructions
ADDITION Register Addition. ADD AX,BX AX=AX+BX 2. Immediate Addition.
Assembly Language for Intel-Based Computers, 4th Edition
Assembly Language for Intel-Based Computers, 4th Edition
Assembly Language for Intel-Based Computers, 5th Edition
Computer Architecture CST 250
EECE.3170 Microprocessor Systems Design I
Chapter 5 Arithmetic and Logic Instructions
Chapter 5: Arithmetic and Logic Instructions
Multiplication and Division Instructions
Multiplication and Division Instructions
Chapter 8: Instruction Set 8086 CPU Architecture
Division instruction.
Presentation transcript:

Introduction Arithmetic instructions are used to perform arithmetic operation such as Addition Subtraction Multiplication Division These operations can be performed on numbers expressed in a variety of formats such as unsigned binary, signed binary, packed or unpacked decimals and signed packed decimal numbers. The flags that are affected by the arithmetic instructions are carry flag, auxiliary carry flag, sign flag, zero flag, parity flag and overflow flag.

ADD instructions This instruction adds the content of the source operand with the destination operand. The result is stored in the destination operand. All flags are affected. ADD ADD operand1, operand 2 operand1 =operand 1 + operand 2 Operand 1: register/memory Operand 2: register/memory/immediate

ADC Instruction This instruction stands for add with carry. This instruction adds the content of source, destination and the carry flag. The result is stored in the destination operand. Example: ADC AX, [BX]

INC instruction This instruction increments the value of register or the data in the memory location by 1. the result is stored in the operand itself. In this carry flag (CF) is not affected. Also in many cases the used of INC instruction generated less machine code, and resulting in faster execution. Examples INC SP This instruction increments the value of SP register by 1. the result is stored in the SP register itself.

SUB Instruction This instruction is used to subtract the value of source operand from the destination operand. The result is stored in the destination operand. If the source operand is larger than the destination operand the resulting borrow is indicated by setting the carry flag. General format SUB destination, source

SUB instructions SUB SUB operand1, operand 2 operand1 =operand 1 - operand 2 operand 1: register/memory operand 2: register/memory/immediate Motaz K. Saad, Dept. of CS7

Example of the ADD and SUB instructions: BYTE1DB24H;Data elements WORD1DW4000H... MOVCL, BYTE1; byte processing MOVDL, 40H ADDCL, DL; register to register SUBCL, 20H; Immediate from register ADD BYTE1, BL; register to memory MOVCX, WORD1; word processing MOV DX, 2000H SUBCX, DX; register from register SUBCX, 124H; Immediate from memory ADDWORD1, DX; register to memory Addition and Subtraction Of Binary Data

Exercise InstructionBeforeAfter (a)MOV CX, 25HCX = 0000HCX=0025 (b)MOV CL, 0CX = FFFFHCX=FF00 (c)MOV AX, BYTE1AX=1234HAX= invalid size (d)ADD DL, BYTE1DX=0120HDX=0125 (e)XCHG AH,ALAX=1234HAX=3412 (f)SUB CX,CXCX=1234HCX=0000 (g)XCHG CX,CXCX=1234HCX=1234 Assume that BYTE1 is defined as DB 05, show the result for the following instructions:

Multiplication instructions For multiplication process, MUL instruction is used for unsigned data IMUL is used for signed data. Both of these instructions affect the Carry and Overflow flag. The format for MUL and IMUL instructions: Observe that MUL/IMUL is a one address instruction, hence it requires an the accumulator register to hold operand1 and result (refer Chapter Instruction format) In IBM PC, the AX register (AL/AH/EAX) acts as accumulator. The multiplication operations are byte times byte, word times word and doubleword times doubleword.

Cont.., For multiplying two one-byte values, the multiplicand (first operand) is in AL register, and the multiplier (second operand) is a byte data in memory or another register that determined by the address field in the MUL/IMUL instruction. Example: MUL DL the operation multiplies the content of AL by the contents of DL. The generated product is in AX. The operation ignores and erases any data that may already be in AH.

Field Size Address field in the MUL/IMUL instruction refers only to the multiplier that will determine the field sizes (whether byte, word, or doubleword). The instruction will use the size of the address field (multiplier) to determine the position of the multiplicand whether it is in AL, AX or EAX A few examples on the MUL instruction together with the multiplier size, multiplicand position and product:

Field Size

MUL  is used for unsigned data Examples on the usage of the MUL instructions using the data as defined below: BYTE1DB80H BYTE2DB40H WORD1DW8000H WORD2DW2000H DWORD1DD H DWORD2DD H (a)MOV AL, BYTE1 ; AL (multiplicand)=80H MULBYTE2 ; byte x byte, product in AX ; 80H x 40H, AX= 2000H (b)MOVAX, WORD1 ; AX (multiplicand)=8000H MULWORD2 ; word x word, product in DX:AX ; 80000H x 2000H, ; DX:AX= H

Example 1 : (MUL Instruction) MOV AL, BYTE1 MULBYTE2; byte x byte, product in AX in the above example, 80H (128) is multiplied with 40H (64) and the result is 2000H (8,192) kept in AX register. MOVAX, WORD1 MULWORD2; word x word, product in DX:AX in the above example, 8000H is multiplied with 2000H and the result, H is kept in a pair of registers, DX:AX.

IMUL  is used with signed data Examples on the usage of the IMUL instructions using the data as defined below: BYTE1DB80H BYTE2DB40H WORD1DW8000H WORD2DW2000H DWORD1DD H DWORD2DD H (a) MOV AL, BYTE1 ; AL (multiplicand)=80H (-ve value) IMUL BYTE2 ; byte x byte, product in AX ; 80H (-ve) x 40H (+ve), AX= E000H (b) MOV AX, WORD1 ; AX (multiplicand)=8000H (-ve value) IMUL WORD2 ; word x word, product in DX:AX ; 80000H (-ve) x 2000H (+ve), ; DX:AX= F H

Example 2 : (Arahan IMUL) MOV AL, BYTE1 IMULBYTE2; byte x byte, product in AX in the above example, BYTE1 and BYTE2 is considered as signed data, that is –128 (80H) and +64 (40H) and the result –8192 (E000H) is stored in the AX register MOVAX, WORD1 IMULWORD2; word x word, product in DX:AX in the above example, WORD1 and WORD2 is considered as signed data, that is 8000H a is –ve value and 2000H is a +ve value. The result, F H is a–ve value and is kept in a pair of registers, DX:AX.

Division Instructions For division operation, the DIV instruction is used for unsigned data whereas IDIV is used for signed data. Its format: The basic divide operations are byte into word, word into doubleword, and doubleword into quad word.

Field Size As in MUL/IMUL, address field in the DIV/IDIV instruction refers to the divisor (second operand) that determines the field sizes. The following example shows the divisor is in the register (example 1) and memory (example2) with a certain size. Example1 : using register addressing mode Example 2 : using direct addressing mode - divisor is predefined in the memory

The following are a few examples of the DIV instruction using the data definition below: BYTE1DB80H; Byte value BYTE2DB16H WORD1DW2000H ; Word value WORD2DW0010H WORD3DW1000H (a) MOV AX, WORD1 ;AX=2000H DIV BYTE1 ;2000H/80H, quotient=40H, remainder=00H ;AL=40H, AH=00H (b) MOV DX, WORD2 ;DX=0010H MOV AX, WORD3 ;AX=1000H,dividend in DX:AX (WORD2:WORD3) ;DX:AX = H DIV WORD1 ; H/2000H remainder:quotient in DX:AX ; 1000H:0080H

DIV Instruction MOVAX, WORD1 DIVBYTE1 In the above example, the value 2000H (8092) will be divided with 80H (128), the quotient, 40H (64) will be kept in the AL register while its remainder, 00H will be kept in the AH register. MOV DX, WORD2 MOV AX, WORD3; dividend in DX:AX (WORD2:WORD3) DIVWORD1; remainder:quotient in DX:AX in the above example, the value H will be divided with 2000H. The remainder, 1000H will be kept in the DX register, whereas its result, 0080H will be kept in the AX register.

The following are a few examples of the IDIV instruction using the data definition below: BYTE1DB80H; Byte value BYTE2DB16H WORD1DW2000H ; Word value WORD2DW0010H WORD3DW1000H (a) MOV AX, WORD1 ; AX=2000H IDIV BYTE1 ; 2000H(+ve)/80H (-ve), ; quotient=C0H (-ve), remainder=00H ; AL=C0H, AH=00H (b) MOV DX, WORD2 ;DX=0010H MOV AX, WORD3 ;AX=1000H,dividend in DX:AX (WORD2:WORD3) ;DX:AX = H (+ve) IDIV WORD1 ; H (+ve)/2000H (+ve) ;remainder:quotient in DX:AX ;1000H:0080H

IDIV Instruction (using the same data definition) MOVAX, WORD1 IDIVBYTE1 in the above example, the value WORD1 is a +ve number whereas BYTE1 is a –ve number. If WORD1 is divided with BYTE1, its result will be a –ve number (64 or C0H) will be kept in the AL register whereas its remainder will be kept in the AH.register MOV DX, WORD2 MOV AX, WORD3; dividend in DX:AX (WORD2:WORD3) DIVWORD1; remainder: quotient in DX:AX in the above example the value H (+ve) will be divided with 2000H (+ve). Its remainder, 1000H (+ve) will be kept in the DX register, whereas its result, 0080H (+ve) will be kept in the AX register.

Divide 8003h by 100h, using 16-bit operands: mov dx,0 ; clear dividend mov ax,8003h ; dividend mov cx,100h ; divisor div cx ; AX = 0080h, DX = 3 Same division, using 32-bit operands: mov edx,0 ; clear dividend mov eax,8003h ; dividend mov ecx,100h ; divisor div ecx ; EAX = h, EDX = 3 DIV Examples

The End