Assembly Language for Intel-Based Computers, 4 th Edition Unpacked and Packed Integers (c) Pearson...
-
Upload
cody-adams -
Category
Documents
-
view
212 -
download
0
Transcript of Assembly Language for Intel-Based Computers, 4 th Edition Unpacked and Packed Integers (c) Pearson...
![Page 1: Assembly Language for Intel-Based Computers, 4 th Edition Unpacked and Packed Integers (c) Pearson Education, 2002. All rights reserved. You may modify.](https://reader036.fdocuments.us/reader036/viewer/2022083009/5697bfc21a28abf838ca5159/html5/thumbnails/1.jpg)
Assembly Language for Intel-Based Assembly Language for Intel-Based Computers, 4Computers, 4thth Edition Edition
Unpacked and Packed Integers
(c) Pearson Education, 2002. 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.
• Chapter corrections (Web) Assembly language sources (Web)
Slides prepared by Kip R. Irvine
Revision date: 07/11/2002
Modified 2006, Dr. Nikolay Metodiev Sirakov
Kip R. Irvine
![Page 2: Assembly Language for Intel-Based Computers, 4 th Edition Unpacked and Packed Integers (c) Pearson Education, 2002. All rights reserved. You may modify.](https://reader036.fdocuments.us/reader036/viewer/2022083009/5697bfc21a28abf838ca5159/html5/thumbnails/2.jpg)
Irvine, Kip R. Assembly Language for Intel-Based Computers, 2003. Web site Examples 2
ASCII and Packed Decimal ArithmeticASCII and Packed Decimal Arithmetic
• Unpacked BCD• ASCII Decimal• AAA Instruction • AAS Instruction • AAM Instruction • AAD Instruction • Packed Decimal Integers• DAA Instruction• DAS Instruction
![Page 3: Assembly Language for Intel-Based Computers, 4 th Edition Unpacked and Packed Integers (c) Pearson Education, 2002. All rights reserved. You may modify.](https://reader036.fdocuments.us/reader036/viewer/2022083009/5697bfc21a28abf838ca5159/html5/thumbnails/3.jpg)
Irvine, Kip R. Assembly Language for Intel-Based Computers, 2003. Web site Examples 3
Unpacked BCDUnpacked BCD
• Binary-coded decimal (BCD) numbers use 4 binary bits to represent each decimal digit
• A number using unpacked BCD representation stores a decimal digit in the lower four bits of each byte• For example, 5,678 is stored as the following sequence
of hexadecimal bytes:
05 06 07 08
![Page 4: Assembly Language for Intel-Based Computers, 4 th Edition Unpacked and Packed Integers (c) Pearson Education, 2002. All rights reserved. You may modify.](https://reader036.fdocuments.us/reader036/viewer/2022083009/5697bfc21a28abf838ca5159/html5/thumbnails/4.jpg)
Irvine, Kip R. Assembly Language for Intel-Based Computers, 2003. Web site Examples 4
ASCII DecimalASCII Decimal
• A number using ASCII Decimal representation stores a single ASCII digit in each byte• For example, 5,678 is stored as the following sequence
of hexadecimal bytes:
35 36 37 38
![Page 5: Assembly Language for Intel-Based Computers, 4 th Edition Unpacked and Packed Integers (c) Pearson Education, 2002. All rights reserved. You may modify.](https://reader036.fdocuments.us/reader036/viewer/2022083009/5697bfc21a28abf838ca5159/html5/thumbnails/5.jpg)
Irvine, Kip R. Assembly Language for Intel-Based Computers, 2003. Web site Examples 5
AAA InstructionAAA Instruction
• The AAA (ASCII adjust after addition) instruction adjusts the binary result of an ADD or ADC instruction. It makes the result in AL consistent with ASCII digit representation.• The Carry value, if any ends up in AH
• Example: Add '8' and '2'
mov ah,0mov al,'8' ; AX = 0038hadd al,'2' ; AX = 006Ahaaa ; AX = 0100h (adjust result)or ax,3030h ; AX = 3130h = '10'
![Page 6: Assembly Language for Intel-Based Computers, 4 th Edition Unpacked and Packed Integers (c) Pearson Education, 2002. All rights reserved. You may modify.](https://reader036.fdocuments.us/reader036/viewer/2022083009/5697bfc21a28abf838ca5159/html5/thumbnails/6.jpg)
Irvine, Kip R. Assembly Language for Intel-Based Computers, 2003. Web site Examples 6
AAS InstructionAAS Instruction
• The AAS (ASCII adjust after subtraction) instruction adjusts the binary result of an SUB or SBB instruction. It makes the result in AL consistent with ASCII digit representation.• It places the Carry value, if any, in AH
• Example: Subtract '9' from '8'
mov ah,0mov al,'8' ; AX = 0038hsub al,'9' ; AX = 00FFhaas ; AX = FF09h (adjust result)pushf ; save Carry flagor al,30h ; AX = FF39h (AL = '9')popf ; restore Carry flag
![Page 7: Assembly Language for Intel-Based Computers, 4 th Edition Unpacked and Packed Integers (c) Pearson Education, 2002. All rights reserved. You may modify.](https://reader036.fdocuments.us/reader036/viewer/2022083009/5697bfc21a28abf838ca5159/html5/thumbnails/7.jpg)
Irvine, Kip R. Assembly Language for Intel-Based Computers, 2003. Web site Examples 7
AAM InstructionAAM Instruction
• The AAM (ASCII adjust after multiplication) instruction adjusts the binary result of a MUL instruction. The multiplication must have been performed on unpacked decimal numbers.
mov bl,05h ; first operandmov al,06h ; second operandmul bl ; AX = 001Ehaam ; AX = 0300h
![Page 8: Assembly Language for Intel-Based Computers, 4 th Edition Unpacked and Packed Integers (c) Pearson Education, 2002. All rights reserved. You may modify.](https://reader036.fdocuments.us/reader036/viewer/2022083009/5697bfc21a28abf838ca5159/html5/thumbnails/8.jpg)
Irvine, Kip R. Assembly Language for Intel-Based Computers, 2003. Web site Examples 8
AAD InstructionAAD Instruction
• The AAD (ASCII adjust before division) instruction adjusts the unpacked decimal dividend in AX before a division operation
.dataquotient BYTE ?remainder BYTE ?.codemov ax,0307h ; dividendaad ; AX = 0025hmov bl,5 ; divisordiv bl ; AX = 0207hmov quotient,almov remainder,ah
![Page 9: Assembly Language for Intel-Based Computers, 4 th Edition Unpacked and Packed Integers (c) Pearson Education, 2002. All rights reserved. You may modify.](https://reader036.fdocuments.us/reader036/viewer/2022083009/5697bfc21a28abf838ca5159/html5/thumbnails/9.jpg)
Irvine, Kip R. Assembly Language for Intel-Based Computers, 2003. Web site Examples 9
Packed Decimal IntegersPacked Decimal Integers
• Packed BCD stores two decimal digits per byte • For example, 12,345,678 can be stored as the
following sequence of hexadecimal bytes:
12 34 56 78
There is no limit on the number of bytes you can use to store a BCD number. Financial values are frequently stored in BCD format, to permit high precision when performing calculations.
![Page 10: Assembly Language for Intel-Based Computers, 4 th Edition Unpacked and Packed Integers (c) Pearson Education, 2002. All rights reserved. You may modify.](https://reader036.fdocuments.us/reader036/viewer/2022083009/5697bfc21a28abf838ca5159/html5/thumbnails/10.jpg)
Irvine, Kip R. Assembly Language for Intel-Based Computers, 2003. Web site Examples 10
DAA InstructionDAA Instruction
• The DAA (decimal adjust after addition) instruction converts the binary result of an ADD or ADC operation to packed decimal format.
• The value to be adjusted must be in AL• Example: calculate BCD 35 + 48
mov al,35hadd al,48h ; AL = 7Dhdaa ; AL = 83h (adjusted)
![Page 11: Assembly Language for Intel-Based Computers, 4 th Edition Unpacked and Packed Integers (c) Pearson Education, 2002. All rights reserved. You may modify.](https://reader036.fdocuments.us/reader036/viewer/2022083009/5697bfc21a28abf838ca5159/html5/thumbnails/11.jpg)
Irvine, Kip R. Assembly Language for Intel-Based Computers, 2003. Web site Examples 11
DAS InstructionDAS Instruction
• The DAS (decimal adjust after subtraction) instruction converts the binary result of a SUB or SBB operation to packed decimal format.
• The value must be in AL• Example: subtract BCD 48 from 85
mov al,85hsub al,48h ; AL = 3Dhdas ; AL = 37h (adjusted)
![Page 12: Assembly Language for Intel-Based Computers, 4 th Edition Unpacked and Packed Integers (c) Pearson Education, 2002. All rights reserved. You may modify.](https://reader036.fdocuments.us/reader036/viewer/2022083009/5697bfc21a28abf838ca5159/html5/thumbnails/12.jpg)
Irvine, Kip R. Assembly Language for Intel-Based Computers, 2003. Web site Examples 12
The EndThe End