Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.
ASCII ADJUST ANDDECIMAL ADJUST                   1
INSTRUCTIONS   AAA - ASCII Adjust After Addition   AAS - ASCII Adjust After Subtraction   AAM - ASCII Adjust After Mult...
INTRODUCTIONThe PC supports BCD format,Uses of BCD   1)No loss of precision   2)Simpler to perform arithmetic   operation ...
Unpacked BCD DataUnpacked BCD representation contains onlyOne decimal digit per byte. The digit isstored in the least sign...
Packed BCD DataPacked BCD representation packs twoDecimal digits into a single byte.Example: Representing 1527            ...
ASCII Adjust After Addition  Adjusts the result of the addition of twounpacked BCD values to create a unpackedBCD result.O...
Operation 2:Clear left nibble form AL.Operation 3:In AHADD 1Operation 4:Set Carry and AuxilaryCarry                       ...
.model small.data   b1 dw 38h   b2 dw 34h.code   mov ax,@data   mov ds,ax   mov ax,b1   ;moving unpacked BCD into ax   mov...
ASCII Adjust After Subtraction  Adjusts the result of the subtraction of twounpacked BCD values to create a unpacked BCDre...
Operation 2:Clear left nibble in AL.Operation 3:Subtracts 1 from AHOperation 4:Set Carry and AuxilaryCarry                ...
Example :d1 contains 34h , d2 contains 38h of byte  type                  Ax            AFMov AL, d1 ;        0034Sub AL, ...
.model small.datab1 dw 38hb2 dw 34h.codemov ax,@datamov ds,axmov ax,b1      ;moving unpacked BCD into axmov bx,b2      ;mo...
ASCII Adjust After Multiplication    For multiplication and Division of ASCII    numbers require that the numbers first b...
Example:AL contains 35H and CL contains 39HInstruction    comment          AX     CLand CL, 0Fh; Convert CL to 09    0035 ...
   Mul operation generates 45 (002Dh) in    AX   AAM divides this value by 10, so quotient    of 04 in AH and remainder ...
.model small.datab1 dw 39h ; 9 in ASCII Formatb2 dw 35h ; 5 in ASCII Format.codemov ax,@datamov ds,axmov ax,b1 ;AX=0039han...
ASCII Adjust Before Division   AAD allows for a 2-Byte Dividend in AX. The    divisor can be only a single Byte(0-9)    ...
Example:AX contains 3238 (28) - DividendCL contains 37 (07) – DivisorInstruction      comment             AX   CLand CL,0F...
   AAD multiplies the AH by 10(0Ah)   Adds the product 20(14h) to the AL and    clears     the AH    The result is 001C...
model small.datab1 dw 3238h ; 28 in ASCII Formatb2 db 37h ; 7 in ASCII Format.codemov ax,@datamov ds,axmov ax,b1 ;AX=3238h...
Decimal Adjust  To adjust the result of packed BCDnumbers which stored in AL.DAA - Decimal Adjust for AdditionDAS - Decima...
Decimal Adjust for AdditionDAA performs the following operations: Operation 1:If AL is >9 (ie) A to F or AuxilaryCarry=1 t...
Operation 2:If AL contains value > 99    or Carry=1 thenADD 60 to AL and set Carry =1   OtherwiseAuxilaryCarry=0 ,carry=0 ...
AL contains   45hBL contains   45hInstruction   Comment             ALADD AL,BL     ; AL=AL+BL             8AhDAA         ...
   DAA checks the rightmost nibble of AL, it    is A so add 6 to AL    Now AL = 90                                      ...
.model small.data    d1 dw 45h ;moving 45 as packed BCD    d2 dw 45h ;moving 45 as packed BCD.code    mov ax,@data    mov ...
Decimal Adjust for SubtractionOperations performed by DAS :If AL is >9 (ie) A to F      or AuxilaryCarry=1 thenSubtract 6 ...
AL contains 80hBL contains 49hInstruction  Comment            ALSUB AL,BL ; AL=AL-BL               37hDAS           ; Adju...
.model small.data    d1 dw 57h    d2 dw 48h.code    mov ax,@data    mov ds,ax    mov ax,d1 ;moving 45 as packed BCD    mov...
THANK U          30
Upcoming SlideShare
Loading in …5
×

Ascii adjust & decimal adjust

13,493 views

Published on

Published in: Entertainment & Humor
  • Be the first to comment

Ascii adjust & decimal adjust

  1. 1. ASCII ADJUST ANDDECIMAL ADJUST 1
  2. 2. INSTRUCTIONS AAA - ASCII Adjust After Addition AAS - ASCII Adjust After Subtraction AAM - ASCII Adjust After Multiply AAD - ASCII Adjust Before Division DAA - Decimal Adjust for Addition DAS - Decimal Adjust for Subtraction 2
  3. 3. INTRODUCTIONThe PC supports BCD format,Uses of BCD 1)No loss of precision 2)Simpler to perform arithmetic operation on small values from keyboardBCD can be stored in two way: Unpacked BCD Packed BCD 3
  4. 4. Unpacked BCD DataUnpacked BCD representation contains onlyOne decimal digit per byte. The digit isstored in the least significant 4 bits; themost significant 4 bits are not relevant tothe value of the represented number.Example: Representing 1527 01 05 02 07h 4
  5. 5. Packed BCD DataPacked BCD representation packs twoDecimal digits into a single byte.Example: Representing 1527 15 27h 5
  6. 6. ASCII Adjust After Addition Adjusts the result of the addition of twounpacked BCD values to create a unpackedBCD result.Operation 1:In ALIf rightmost nibble is >9 (ie)A to F Or AuxilaryFlag=1ADD 6 to rightmost nibble 6
  7. 7. Operation 2:Clear left nibble form AL.Operation 3:In AHADD 1Operation 4:Set Carry and AuxilaryCarry 7
  8. 8. .model small.data b1 dw 38h b2 dw 34h.code mov ax,@data mov ds,ax mov ax,b1 ;moving unpacked BCD into ax mov bx,b2 ;moving unpacked BCD into bx add ax,bx aaa ;adjusting unpacked BCD after addition or ax,3030h end 8
  9. 9. ASCII Adjust After Subtraction Adjusts the result of the subtraction of twounpacked BCD values to create a unpacked BCDresult.Operation 1: a)AAS checks the rightmost nibble in AL b)If rightmost nibble is >9 (ie)A to F Or AuxilaryFlag=1 c)Then Subtract 6 from rightmost nibble 9
  10. 10. Operation 2:Clear left nibble in AL.Operation 3:Subtracts 1 from AHOperation 4:Set Carry and AuxilaryCarry 10
  11. 11. Example :d1 contains 34h , d2 contains 38h of byte type Ax AFMov AL, d1 ; 0034Sub AL, d2; 00fc 1AAS ; ff06 1 since the rightmost digit of AL is c , subtract 6 from AL Subtract 1 from ah, set AF and CF flags The answer is -4, is ff06 in 10’s complement 11
  12. 12. .model small.datab1 dw 38hb2 dw 34h.codemov ax,@datamov ds,axmov ax,b1 ;moving unpacked BCD into axmov bx,b2 ;moving unpacked BCD into bxsub ax,bxaas ;adjusting unpacked BCD after subtractionor ax,3030hend 12
  13. 13. ASCII Adjust After Multiplication For multiplication and Division of ASCII numbers require that the numbers first be converted into unpacked BCD format. Before Multiplication First clear the leftmost nibble in each Byte. After Multiplication AAM performs the following operations 1) Divides AL value by 10 (0AH) 2) Stores Quotient in AH 3) Store Remainder in AL 13
  14. 14. Example:AL contains 35H and CL contains 39HInstruction comment AX CLand CL, 0Fh; Convert CL to 09 0035 39and AL,0Fh; Convert AL to 05 0005 09mul CL; Multiply AL by CL 002DAAM ; Convert to unpacked 0405 BCDOr AX,3030h; covert to ASCII 3435 14
  15. 15.  Mul operation generates 45 (002Dh) in AX AAM divides this value by 10, so quotient of 04 in AH and remainder of 05 in AL OR instruction converts the unpacked BCD to ASCII format 15
  16. 16. .model small.datab1 dw 39h ; 9 in ASCII Formatb2 dw 35h ; 5 in ASCII Format.codemov ax,@datamov ds,axmov ax,b1 ;AX=0039hand AL,0fh ;AX=0009hmov bx,b2 ;BX=0035hand bl,0fh ;BX=0005hmul bx ;AX=002Dhaamor ax,3030hend 16
  17. 17. ASCII Adjust Before Division AAD allows for a 2-Byte Dividend in AX. The divisor can be only a single Byte(0-9) Before Division First clear the leftmost nibble in each Byte. Operations done by AAD instruction 1) AAD multiplies the AH by 10(0Ah). 2) Then adds the product to AL and clears the AH After AAD , division is performed. 17
  18. 18. Example:AX contains 3238 (28) - DividendCL contains 37 (07) – DivisorInstruction comment AX CLand CL,0Fh; convert to unpacked 3238 07 BCDand AX,0F0Fh; convert to unpacked 0208 07 BCDAAD; convert to binary 001Cdiv CL; divide by 7 0004 18
  19. 19.  AAD multiplies the AH by 10(0Ah) Adds the product 20(14h) to the AL and clears the AH The result is 001Ch, is hex representation of decimal 28 Then division is performed. Remainder stored in AH, Quotient stored in AL 19
  20. 20. model small.datab1 dw 3238h ; 28 in ASCII Formatb2 db 37h ; 7 in ASCII Format.codemov ax,@datamov ds,axmov ax,b1 ;AX=3238hand ax,0f0fh ;AX=0208hmov cl,b2 ;CL=37hand cl,0fh ;CL=07haad ; AX= 001cdiv cl ; AX=0004or ax,3030h; AX=3034end 20
  21. 21. Decimal Adjust To adjust the result of packed BCDnumbers which stored in AL.DAA - Decimal Adjust for AdditionDAS - Decimal Adjust for Subtraction 21
  22. 22. Decimal Adjust for AdditionDAA performs the following operations: Operation 1:If AL is >9 (ie) A to F or AuxilaryCarry=1 thenADD 6 to ALSet AuxilaryCarry=1 22
  23. 23. Operation 2:If AL contains value > 99 or Carry=1 thenADD 60 to AL and set Carry =1 OtherwiseAuxilaryCarry=0 ,carry=0 23
  24. 24. AL contains 45hBL contains 45hInstruction Comment ALADD AL,BL ; AL=AL+BL 8AhDAA ; Adjust packed BCD 90h addition 24
  25. 25.  DAA checks the rightmost nibble of AL, it is A so add 6 to AL Now AL = 90 25
  26. 26. .model small.data d1 dw 45h ;moving 45 as packed BCD d2 dw 45h ;moving 45 as packed BCD.code mov ax,@data mov ds,ax mov ax,d1 mov bx,d2 add ax,bx daa ;adjusting the packed BCD after addition end 26
  27. 27. Decimal Adjust for SubtractionOperations performed by DAS :If AL is >9 (ie) A to F or AuxilaryCarry=1 thenSubtract 6 from ALSet Carry=1OtherwiseAuxilaryCarry=0 ,carry=0 27
  28. 28. AL contains 80hBL contains 49hInstruction Comment ALSUB AL,BL ; AL=AL-BL 37hDAS ; Adjust packed BCD 31h Subtraction 28
  29. 29. .model small.data d1 dw 57h d2 dw 48h.code mov ax,@data mov ds,ax mov ax,d1 ;moving 45 as packed BCD mov bx,d2 ;moving 45 as packed BCD sub ax,bx das ; adjusting the packed BCD after subraction end 29
  30. 30. THANK U 30

×