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.

Slides:



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

Assembly Language for x86 Processors 6th Edition
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.
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.
Assembly Language for Intel-Based Computers, 5 th Edition Chapter 7: Integer Arithmetic (c) Pearson Education, All rights reserved. You may.
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
Assembly Language for Intel-Based Computers, 4 th Edition Chapter 7: Integer Arithmetic (c) Pearson Education, All rights reserved. You may modify.
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, 4 th Edition Chapter 7: Integer Arithmetic (c) Pearson Education, All rights reserved. You may modify.
Assembly Language for Intel-Based Computers
CE302 Outline Multiplication Division Program Segment Prefix Command Line Parameters.
Assembly Language – Lab 5
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.
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.
Multiplication and Division Instructions & the 0Ah function.
Microprocessors Monday, Apr. 13 Dr. Asmaa Farouk Faculty of Engineering, Electrical Department, Assiut University.
Sahar Mosleh California State University San MarcosPage 1 Review.
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.
CT215: Assembly Language Programming
Assembly Language for Intel-Based Computers, 4 th Edition Unpacked and Packed Integers (c) Pearson Education, All rights reserved. You may modify.
Assembly Language for x86 Processors 6th Edition Chapter 7: Integer Arithmetic (c) Pearson Education, All rights reserved. You may modify and copy.
Arithmetic and Logic Instructions
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.
Assembly Language for Intel-Based Computers, 5 th Edition Chapter 7: Integer Arithmetic (c) Pearson Education, All rights reserved. You may.
Assembly Language for x86 Processors 7th Edition
ICS 312 SET 10 Multiplication & Division & input using function 0Ah.
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.
Multiplication and Division instructions Dr.Hadi AL Saadi.
Data Transfers, Addressing, and Arithmetic
Assembly Language for Intel-Based Computers, 5th Edition
Assembly Language for x86 Processors 7th Edition
Basic Assembly Language
Multiplication and Division Instructions
CS-401 Computer Architecture & Assembly Language Programming
4.2 Arithmetic Instructions
INSTRUCTION SET OF 8086 PAWAN KUMAR SINGH.
CS 301 Fall 2002 Assembly Instructions
X86’s instruction sets.
Chapter 4: Instructions
Morgan Kaufmann Publishers Computer Organization and Assembly Language
Microprocessor and Assembly Language
Multiplication and Division Instructions
Assembly Language for Intel-Based Computers, 4th Edition
Assembly Language for Intel-Based Computers, 4th Edition
Assembly Language for Intel-Based Computers, 5th Edition
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
Division instruction.
Presentation transcript:

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

MUL Instruction Note that the product is stored in a register (or group of registers) twice the size of the operands. The operand can be a register or a memory operand

MUL Instruction MultiplicandMultiplierProduct ALr/m8AX r/m16DX:AX EAXr/m32EDX:EAX

MUL Examples Moval, 5h Movbl, 10h Mulbl; AX = 0050h, CF = 0 (no overflow - the Carry flag is 0 because the upper half of AX is zero)

MUL Examples.data Val1WORD2000h Val2WORD0100h.code Movax, val1 Mulval2;DX:AX = h, CF = 1 (Carry flag is 1 because DX is not equal to zero)

IMUL Instruction (Signed Multiply) Has the same syntax and uses the same operands as the MUL instruction except that it preserves the sign of the product.

IMUL Instruction IMUL sets the Carry and Overflow flags if the high-order product is not a sign extension of the low-order product. Moval, 48 Movbl, 4 Imul bl;AX = 00C0h, OF = 1 AH is not a sign extension of AL, so the Overflow flag is set.

IMUL Instruction Mul al, -4 Movbl, 4 Imulbl; AX = FFF0h, OF = 0 AH is a sign extension of AL (the signed result fits within AL), so the Overflow flag is clear.

DIV Instruction (Unsigned Divide) Performs 8-, 16-, and 32-bit division on unsigned integers. DIV r/m8 DIV r/m16 DIV r/m32

DIV Instruction DividendDivisorQuotientRemainder AXr/m8ALAH DX:AXr/m16AXDX EDX:EAXr/m32EAXEDX

DIV Instruction dividendEDXEAX (quotient) ___________________________= divisor r/m32 EDX(remainder)

DIV Examples 8-bit Unsigned Division Movax,0083h;dividend Movbl, 2h;divisor Divbl; AL = 41h, AH = 01h Quotient is 41h, remainder is 1

DIV Examples Movdx,0;clear dividend, high Movax, 8003h;dividend, low Movcx, 100h;divisor Divcx;ax = 0080h, dx = 0003h Quotient = 80h, remainder = 3

Signed Integer Division CBW – convert Byte to word – Extends the sign bit of AL into the AH register.data BytevalSBYTE-65.code moval,byteval; AL = 9Bh cbw; AX = FF9Bh

Sign Extension Instructions CBW –-Convert byte to word CWD –Convert word to double CDQ –-Convert double to quadword

IDIV Instruction (Signed Division) Performs signed integer division, using the same operands as the DIV instruction The dividend must be sign-extended into the high order register before IDIV executes.

IDIV Examples.data BytevalSBYTE-48.code moval, byteval;dividend cbw;extend AL into AH movbl, 5;divisor idivbl;AL = -9, AH = -3

Divide Overflow If the quotient is too large to fit into the destination operand, a divide overflow results. This causes a CPU interrupt, and the current program halts. Movax, 1000h Movbl, 10h Divbl;AL cannot hold 100h

DIV Overflow Can use 16-bit divisor to reduce the possibility of divide overflow. Movax, 1000h Movdx, 0;clear DX Movbx, 10h Divbx;AX = 0100h

Dividing by Zero Put a check of the divisor to compare to zero. If divisor is zero, jump to an error return and skip the code with the divide.

Implementing Arithmetic Expressions Implement Var4 = (Var1 + Var2) * Var3 Moveax,var1 Addeax, var2 Mulvar3;EAX = EAX*Var3 Movvar4, eax

Extended Addition How do you add 128-bit integers in C? How do you add 128-bit integers in Assembly? ADC (Add with Carry) –Adds both a source operand and the contents of the carry flag to a destination operand. Movdl,0 Moval, 0FFh Addal, 0FFh;AL = FEh ADCdl,0;DL = 1

Subtract with Borrow SBB –Subtracts both a source operand and the value of the carry flag from a destination operand. Movedx, 1;upper half Moveax, 0;lower half Subeax,1;subtract 1 Sbbedx,0;subtract upper half

Adding ASCII Digits ASCII values can be added digit by digit. It is slow, but allows processing of large numbers. The high 4 bits of an unpacked decimal integer are always zero – they are always 0011 with ASCII

Necessary adjustments AAA (ASCII Adjust after Addition) Adjust the binary result of an ADD or ADC instruction. Movah,0 Moval, ‘8’;AX = 0038h Addal, ‘2’;AX = 006Ah Aaa;AX = 0100h Orax, 3030h;AX = 3130h = ’10’

Related Instructions AAS –ASCII Adjust after Subtraction AAM –ASCII Adjust after Multiplication AAD –ASCII Adjust after Division

Packed Decimal Numbers DAA Instruction –Decimal Adjust after Addtion DAS Instruction –Decimal Adjsut after Subtraction