Sie sind auf Seite 1von 15

ASCII ADJUST INSTRUCTIONS

RAMESH H R Asst.prof. Dept of TE

COORG INSTITUTE OF TECHNOLOGY,PONNAMPET

AAA : ASCII Adjust After Addition

Executed after an ADD instruction that adds two ASCII operands

AH must be cleared before addition If AL is between 0 to 9 and AF is 0 AAA sets the 4 higher order bits of AL to 0. If the lower digits of AL is between 0 to 9 and AF is SET, 1. 06 is added to AL. 2. The upper 4-bits of AL is cleared and 3. AH is incremented by 1

AAA : ASCII Adjust After Addition


If value in the lower nibble of AL is greater than 9 1. AL is incremented by 06H 2. AH is incremented by 1 3. AF and CF flags are set to 1 4. Higher 4 bits of AL is cleared

Example:

MOV AL,39H; AL=39H MOV BL,32H;BL=32H ADD AL,BL; RESULT AL=6BH AAA; AH=01H, AL=01H,CF=AF=1
NOTE:

6B

=11

=0101

(HEX)

(PACKED BCD) (UNPACKED BCD)

AAS : ASCII Adjust After Subtraction

Used after subtraction Used to adjust the hexadecimal answer,which is present in AL register to an unpacked BCD answers. The unpacked answer will be stored in AH and AL register.

AH must be cleared before addition If AL is between 0 to 9 and AF is 0 AAS sets the 4 higher order bits of AL to 0.

AAS : ASCII Adjust After Subtraction


If the lower digits of AL is between 0 to 9 and AF is SET, 1. Subtract 6 from AL(AL=AL-6). 2. Subtract 1 from AH(AH=AH-1) 2. The upper 4-bits of AL is cleared and If value in the lower nibble of AL is greater than 9 1. Subtract 6 from AL (AL = AL-6) 2. Subtract 1 from AH (AH = AH-1) 3. AF and CF flags are set to 1 4. Higher 4 bits of AL is cleared

Example:

MOV AH,00H ;AH=00 MOV AL,39H ; AL=39H MOV BL,32H ; BL=32H SUB AL,BL ; AL=07H AAS ;do not alter the contents of AL and AH register

AAM : ASCII Adjust After Multiplication

Used to adjust hexadecimal product which is present in AX register to unpacked BCD format. Multiplication has to performed on two unpacked BCD numbers. Only S , Z , P flags will be affected Operation:
AL

= AL mod 10 AH = AL/10 (only integer part)

Examples:

MOV AL,09H; AL=09H MOV BL,09H; BL=09H MUL BL ; AH=00,AL=51H AAM ;AH=08 ,AL=01 HLT
AL=AL

MOD 10; AL=51H MOD 10 AL=01H AH = AL/10 ; AH = 51H/10 AH = 08H

AAM : ASCII Adjust before division


Used before division to adjust the unpacked BCD data to hexadecimal format Result will be obtained in unpacked BCD format.
Quotient

in AL register Remainder in AH register Operation: AL =AH *10 + AL AH= 00H

Examples

MOV AX,0205H ;AX=0205 MOV BL,06H ; BL=06 AAD ;AX= 0019H DIV BL ; AH=01,AL=04
AX=0205H

AL =AH*10 +AL 02*10+05 =19H AH= 00H AX = 0019H

DAA : Decimal Adjust After Addition

Used after packed BCD addition. Used to adjust hexadecimal result to packed BCD format 8 bit result must be stored in AL register. Operation:
if lower nibble of AL>9 or AF=1 Then AL=AL+06 ;AF=1

Else do not alter the lower nibble of AL

If upper nibble of AL>9 or CF=1 Then AL=AL+60H ;CF=1

Else do not alter upper nibble of AL

Example

MOV AL,42H ;AL=42H MOV BL,29H ;BL=29H ADD AL,BL ;AL=6BH DAA ;AL=71 ;which is packed BCD format result for 42+29=71
Flags

: AF=1,PF=1, CF=SF=ZF=0, OF=undefined

DAS : Decimal Adjust After Subtraction

Used after subtracting two packed BCD number Result will be stored in AL register in hexadecimal format. Used to convert hexadecimal result to packed BCD Operation:
if lower nibble of AL>9 or AF=1 Then AL=AL-06 ;AF=1

Else do not alter the lower nibble of AL

If upper nibble of AL>9 or CF=1 Then AL=AL-60H ;CF=1

Else do not alter upper nibble of AL

Example

MOV AL,85H ;AL=85H MOV BL,57H ;BL=57H SUB AL,BL ;AL=2EH DAS ;AL=28 ;which is packed BCD format result for 85-57=28
Flags

: AF=1,PF=1, CF=SF=ZF=0, OF=undefined

Das könnte Ihnen auch gefallen