Assembly Language for Intel-Based Computers Chapter 7: Integer Arithmetic (c) Pearson Education, 2006-2007. All rights reserved. You may modify and copy.

Slides:



Advertisements
Similar presentations
Integer Arithmetic: Multiply, Divide, and Bitwise Operations
Advertisements

CSC 221 Computer Organization and Assembly Language Lecture 21: Conditional and Block Structures: Assembly Programs.
Assembly Language for Intel-Based Computers, 4 th Edition Chapter 1: Basic Concepts (c) Pearson Education, All rights reserved. You may modify and.
Assembly Language for x86 Processors 6th Edition Chapter 5: Procedures (c) Pearson Education, All rights reserved. You may modify and copy this slide.
NEG Instruction Change operand content into two’s complement (negative value) and stored back into its operand mov bl, b neg bl; bl = mov.
Department of Computer Science and Software Engineering
Computer Organization & Assembly Language
Web siteWeb site ExamplesExamples Irvine, Kip R. Assembly Language for Intel-Based Computers, MUL Instruction The MUL (unsigned multiply) instruction.
Assembly 02. Outline mov Command Registers Memory EFLAGS Arithmetic 1.
Assembly Language for Intel-Based Computers, 4 th Edition Chapter 6: Conditional Processing (c) Pearson Education, All rights reserved. You may modify.
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, 4th Edition
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.
Assembly Language for Intel-Based Computers, 5 th Edition Chapter 1: Basic Concepts (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
Introduction to Computer Engineering by Richard E. Haskell Shift and Rotate Instructions Module M16.2 Section 10.3.
Assembly Language – Lab 5
Assembly Language for x86 Processors 6th Edition
Assembly Language for Intel-Based Computers, 5 th Edition Chapter 1: Basic Concepts (c) Pearson Education, All rights reserved. You may modify.
Sahar Mosleh California State University San MarcosPage 1 Applications of Shift and Rotate Instructions.
Assembly Language for x86 Processors 7th Edition
Assembly Language for Intel-Based Computers, 6 th Edition Chapter 8: Advanced Procedures (c) Pearson Education, All rights reserved. You may.
Microprocessors Monday, Apr. 13 Dr. Asmaa Farouk Faculty of Engineering, Electrical Department, Assiut University.
CSC 221 Computer Organization and Assembly Language Lecture 12: Addressing Modes in Assembly.
Assembly Language for Intel-Based Computers, 6 th Edition Chapter 6: Conditional Processing (c) Pearson Education, All rights reserved. You may modify.
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.
Assembly 05. Outline Bit mapping Boolean logic (review) Bitwise logic Bit masking Bit shifting Lookup table 1.
Chapter 7: Integer Arithmetic. 2 Chapter Overview Shift and Rotate Instructions Shift and Rotate Applications Multiplication and Division Instructions.
Lecture 12 Integer Arithmetic Assembly Language for Intel-Based Computers, 4th edition Kip R. Irvine.
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
Assembly Language for Intel-Based Computers, 4 th Edition Chapter 5: Procedures Lecture 19: Procedures Procedure’s parameters (c) Pearson Education, 2002.
Chapter 7 Bit Manipulation. 7.1 Logical Operations.
CSC 221 Computer Organization and Assembly Language Lecture 15: STACK Related Instructions.
Assembly Language for Intel-Based Computers, 4 th Edition Lecture 22: Conditional Loops (c) Pearson Education, All rights reserved. You may modify.
Multiplication and Division instructions Dr.Hadi AL Saadi.
Assembly Language Programming IV: shift, struct, recursion
Assembly Language for x86 Processors 6th Edition
Assembly Language for Intel-Based Computers, 5th Edition
Assembly Language for x86 Processors 7th Edition
Microprocessor Systems Design I
Assembly Language for Intel-Based Computers, 5th Edition
Multiplication and Division Instructions
Chapter 4: Instructions
Computer Organization and Assembly Languages Yung-Yu Chuang 2005/11/17
Morgan Kaufmann Publishers Computer Organization and Assembly Language
Multiplication and Division Instructions
Assembly Language for Intel-Based Computers, 4th Edition
Assembly Language for Intel-Based Computers, 5th Edition
Shift & Rotate Instructions)
Assembly Language for Intel-Based Computers, 4th Edition
Assembly Language for Intel-Based Computers, 5th Edition
Shift, Multiply, and Divide
Chapter 5 Arithmetic and Logic Instructions
Multiplication and Division Instructions
Multiplication and Division Instructions
Division instruction.
Shift and Rotate Instructions.
Presentation transcript:

Assembly Language for Intel-Based Computers Chapter 7: Integer Arithmetic (c) Pearson Education, All rights reserved. You may modify and copy this slide show for your personal use, or for use in the classroom, as long as this copyright statement, the author's name, and the title are not changed. Slides prepared by the author Revision date: June 4, 2006 Kip R. Irvine

Question 1 SHL performs unsigned multiplication efficiently when the multiplier is a power of 2. Write a code fragment to compute EAX*36 by using only SHL and ADD instructions.

Question 1 SHL performs unsigned multiplication efficiently when the multiplier is a power of 2. Write a code fragment to compute EAX*36 by using only SHL and ADD instructions. EAX * 36 = EAX * (32 + 4) = (EAX * 32)+(EAX * 4)

Question 2 Multiply AX by 26, using shifting and addition instructions.

Question 3 Irvine, Kip R. Assembly Language for Intel-Based Computers 5/e, Isolating a Bit String The MS-DOS file date field packs the year, month, and day into 16 bits: Use AND and Shifting instructions to store the month field to AL.

and >shift 5 bits to the right Isolating a Bit String: Method One mov ax, dx and ax, b shr ax, 5

Irvine, Kip R. Assembly Language for Intel-Based Computers 5/e, Isolating a Bit String: Method Two The MS-DOS file date field packs the year, month, and day into 16 bits: mov ax,dx; make a copy of DX shr ax,5; shift right 5 bits and al, b; clear bits 4-7 mov month,al; save in month variable Isolate the Month field:

Irvine, Kip R. Assembly Language for Intel-Based Computers 5/e, Shifting Multiple Doublewords Shifts an array of 3 doublewords 1 bit to the right. Question >

Irvine, Kip R. Assembly Language for Intel-Based Computers 5/e, Shifting Multiple Doublewords Shifts an array of 3 doublewords 1 bit to the right. Example, shift 3 BYTES 1 bit to the right CL BL AL > shr AL, 1? But we need the LSB (least significant bit) of BL. Question 4

shr AL, 1 rcr AL, 1

Irvine, Kip R. Assembly Language for Intel-Based Computers 5/e, Shifting Multiple Doublewords Shifts an array of 3 doublewords 1 bit to the right. Example, shift 3 BYTES 1 bit to the right CL BL AL > shr CL, 1? Question 4

Irvine, Kip R. Assembly Language for Intel-Based Computers 5/e, Shifting Multiple Doublewords Shifts an array of 3 doublewords 1 bit to the right. Example, shift 3 BYTES 1 bit to the right CL BL AL > shr CL, 1? the LSB (least significant bit) of CL is assigned to CF. Question 4

Irvine, Kip R. Assembly Language for Intel-Based Computers 5/e, Shifting Multiple Doublewords Shifts an array of 3 doublewords 1 bit to the right. Example, shift 3 BYTES 1 bit to the right CL BL AL > shr CL, 1 ;the LSB of CL is assigned to CF. rcr BL, 1 rcr AL, 1 Question 4

Irvine, Kip R. Assembly Language for Intel-Based Computers 5/e, Shifting Multiple Doublewords Shifts an array of 3 doublewords 1 bit to the right..data ArraySize = 3 array DWORD ArraySize DUP( h) ; code mov esi,0 shr array[esi + 8],1; high dword rcr array[esi + 4],1; middle dword, include Carry rcr array[esi],1; low dword, include Carry Question 4

Question h * 1000h, using 32-bit operands:

Question 5

mov eax,12345h mov ebx,1000h mul ebx ; EDX:EAX = h, CF=0

Question 6 8-bit division of –67 by 5 Assume we have: mov al, -67

Question 6 Default Operands:

Question 6 8-bit division of –67 by 5 mov al, -67 cbw mov bl, 5 idiv bl