Division instruction.

Slides:



Advertisements
Similar presentations
Introduction to Computer Engineering by Richard E. Haskell Multiplication and Division Instructions Module M16.4 Section 10.4.
Advertisements

Assembly Language for x86 Processors 6th Edition
Department of Computer Science and Software Engineering
Computer Organization & Assembly Language
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.
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
Integer Arithmetic Computer Organization & Assembly Language Programming Dr Adnan Gutub aagutub ‘at’ uqu.edu.sa [Adapted from slides of Dr. Kip Irvine:
Integer Arithmetic COE 205 Computer Organization and Assembly Language
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.
Assembly Language – Lab 5
Multiplication and Division Instructions & the 0Ah function.
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.
Assembly Language for Intel-Based Computers Chapter 7: Integer Arithmetic (c) Pearson Education, All rights reserved. You may modify and copy.
CT215: Assembly Language Programming
Assembly Language for x86 Processors 6th Edition Chapter 7: Integer Arithmetic (c) Pearson Education, All rights reserved. You may modify and copy.
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,
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.
Microprocessor & Assembly Language Arithmetic and logical Instructions.
K.K. Leung Fall 2008Introductory Pentium Programming1 Pentium Architecture: Introductory Programming Kin K. Leung
Multiplication and Division instructions Dr.Hadi AL Saadi.
Computer Architecture and Assembly Language
Assembly Lab 3.
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
4.2 Arithmetic Instructions
INSTRUCTION SET OF 8086 PAWAN KUMAR SINGH.
CS 301 Fall 2002 Assembly Instructions
X86’s instruction sets.
Chapter 4: Instructions
Computer Organization and Assembly Languages Yung-Yu Chuang 2005/11/17
Morgan Kaufmann Publishers Computer Organization and Assembly Language
Microprocessor and Assembly Language
Introduction to Intel x86-64 Assembly, Architecture, Applications, & Alliteration Xeno Kovah – 2014 xkovah at gmail.
Multiplication and Division Instructions
Assembly Language for Intel-Based Computers, 4th Edition
Shift & Rotate Instructions)
More IA32 (AKA Pentium) Instructions
Assembly Language for Intel-Based Computers, 4th Edition
Assembly Language for Intel-Based Computers, 5th Edition
Computer Architecture and System Programming Laboratory
EECE.3170 Microprocessor Systems Design I
Chapter 5 Arithmetic and Logic Instructions
Multiplication and Division Instructions
Multiplication and Division Instructions
Computer Architecture and System Programming Laboratory
Presentation transcript:

Division instruction

DIV Instruction The DIV (unsigned divide) instruction performs 8 bit, 16 bit , and 32 bit division on unsigned integers. Div r/m8 Div r/m16 Div r/m32 The following illustration shows EDX:EAX as the default dividend when a 32- bit divisor is used. EDX EAX = eax quotient r/m32 edx remainder Dividend Divisor Quotient Reminder AX r/m8 AL AH DX:AX r/m16 DX EDX:EAX r/m32 EAX EDX

Example 1: The following instruction perform 8-bit unsigned division (83h/2), producing a quotient of 41h and a remainder of 1. mov ax, 0083h mov bl, 2 div bl Example 2: The following instruction perform 16-bit unsigned division (8003h/100h), producing a quotient of 80h and a remainder of 3. DX contains the high pat of the dividend, so it must be cleared before the div instruction executes. mov dx, 0 mov ax, 8003h mov cx, 100h div cx

Signed Integer Division CBW, CWD, CDQ Instructions Before discussing signed integer division, we need to look at three instructions that perform integer signed extension. The CBW instruction extends the sign bit of AL into the ah register. This preserves the number’s sign .data ByteVal sbyte -101 ; 9Bh .code mov al, ByteVal ; AL = 9Bh cbw ; AX = FF9Bh In order words, 9Bh and FF9BH both equal -65. The only difference between the two is their storage size

The CWD (convert word to doubleword) instruction extends the sign bit of AX into the DX register .data WordVal sword -101 ; FF9Bh .code mov ax, WordVal ; AX = FF9Bh cwd ; DX:AX = FFFFFF9Bh The CDQ (convert doubleword to quadword) instruction extends the sign bit of EAX into the EDX register DwordVal sword -101 ; FFFFF9Bh mov eax, DwordVal cdq ; EDX:EAX = FFFFFFFFFFFFF9Bh

The IDIV instruction The IDIV (signed divide instruction) performs signed integer division, using the same operands as the DIV instruction. When doing 8-bit division, you must sign-extend the dividend into AH before IDIV executes, (The CBW instruction can be used). Example: We divide -48 by 5. After IDIV executes, the quotient in AL is -9 and the remainder in AH is -3. .data ByteVal sbyte -48 .code mov al, ByteVal ; dividend cbw ; AL into AH mov bl, 5 ; Divisor idiv bl ; AL = -9, AH = -3

Example: Divide -5000 by 256 Similarly, 16-bit division requires that AX to be signed extended into DX .data WordVal sword -5000 .code mov ax, WordVal ; Dividend, low cwd ; extend AX into DX mov bx, 256 ; divisor idiv bx ; quotient AX = -19 ; remainder DX = -136

mov eax, dwordVal ; dividend, low cdq ; extend EAX into EDX Example: Divide -50000 by 256 Similarly, 32-bit division requires that EAX be signed extended into EDX. .data dwordVal SWORD -50000 .code mov eax, dwordVal ; dividend, low cdq ; extend EAX into EDX mov ebx, 256 ; divisor idiv ebx ; quotient EAX = -195 ; remainder EDX = -80 For both DIV and IDIV, all of the arithmetic status flags are undefined after the operations