Presentation is loading. Please wait.

Presentation is loading. Please wait.

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

Similar presentations


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

1 Assembly Language for Intel-Based Computers Chapter 7: Integer Arithmetic (c) Pearson Education, 2006-2007. 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

2 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.

3 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)

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

5 Question 3 Irvine, Kip R. Assembly Language for Intel-Based Computers 5/e, 2007. 5 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.

6 0010 0110 0110 1010 and0000 0001 1110 0000 ---------------------------------------- 0000 0000 0110 0000 0000 0000 0110 0000 ->shift 5 bits to the right Isolating a Bit String: Method One mov ax, dx and ax, 0000 0001 1110 0000b shr ax, 5

7 Irvine, Kip R. Assembly Language for Intel-Based Computers 5/e, 2007. 7 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,00001111b; clear bits 4-7 mov month,al; save in month variable Isolate the Month field:

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

9 Irvine, Kip R. Assembly Language for Intel-Based Computers 5/e, 2007. 9 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 0011 0110 1011 1110 0011 0111 -> 0001 1011 0101 1111 0001 1011 shr AL, 1? But we need the LSB (least significant bit) of BL. Question 4

10 shr AL, 1 rcr AL, 1

11 Irvine, Kip R. Assembly Language for Intel-Based Computers 5/e, 2007. 11 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 0011 0110 1011 1110 0011 0111 -> 0001 1011 0101 1111 0001 1011 shr CL, 1? Question 4

12 Irvine, Kip R. Assembly Language for Intel-Based Computers 5/e, 2007. 12 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 0011 0110 1011 1110 0011 0111 -> 0001 1011 0101 1111 0001 1011 shr CL, 1? the LSB (least significant bit) of CL is assigned to CF. Question 4

13 Irvine, Kip R. Assembly Language for Intel-Based Computers 5/e, 2007. 13 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 0011 0110 1011 1110 0011 0111 -> 0001 1011 0101 1111 0001 1011 shr CL, 1 ;the LSB of CL is assigned to CF. rcr BL, 1 rcr AL, 1 Question 4

14 Irvine, Kip R. Assembly Language for Intel-Based Computers 5/e, 2007. 14 Shifting Multiple Doublewords Shifts an array of 3 doublewords 1 bit to the right..data ArraySize = 3 array DWORD ArraySize DUP(99999999h) ; 1001 1001....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

15 Question 5 12345h * 1000h, using 32-bit operands:

16 Question 5

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

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

19 Question 6 Default Operands:

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


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

Similar presentations


Ads by Google