The DAS instruction

Decimal adjust of the AL register after subtraction.

The DAS instruction format

InstructionDescription
DASDecimal adjust of the AL register after subtraction.

Adjusts the result of subtracting two packed BCD values to create a packed BCD result. The al register is an implied source and destination operand. The das instruction is useful only when it follows the sub instruction, which subtracts one 2-digit packed BCD value from another and stores the result in the al register. Then the das instruction adjusts the contents of the al register so that it contains a correct 2-digit packed BCD result. If a decimal borrow is detected, the CF and AF flags are set accordingly.

Usage example: 87 - 18

title Author: Evgeny Sergeevich Dovgopolov

.model small
.stack 100h

code segment public        ; Start of the code segment
    assume cs:code

    main proc              ; Start of the main procedure
        mov     al, 87h    ; Copy the packed value 87 into the al register
        sub     al, 18h    ; Subtract the packed value 18 from the al register
        das                ; Perform the decimal adjust of the al register
        mov     bx, ax     ; Copy the value of the ax register into the bx register

        mov     ah, 02h    ; Copy the console output function number into ah
        mov     cl, 4      ; Copy the number 4 into the cl register
        shl     bx, cl     ; Shift the bits in bx to the left by the amount specified in cl
        mov     dl, bh     ; Copy the number from the bh register into the dl register
        or      dl, 30h    ; Convert the value in the dl register into an ASCII digit
        int     21h        ; Call the interrupt
        shr     bx, cl     ; Shift the bits in bx to the right by the amount specified in cl
        and     bl, 0Fh    ; Clear the high nibble of the bl register
        mov     dl, bl     ; Copy the number from the bl register into the dl register
        or      dl, 30h    ; Convert the value in the dl register into an ASCII digit
        int     21h        ; Call the interrupt

        mov     ax, 4C00h  ; Copy the process termination function number into ah and the value into al
        int     21h        ; Call the interrupt
    main endp              ; End of the main procedure

code ends                  ; End of the code segment
end main                   ; End of file. The main procedure is the entry point

Example taken from the textbook "HANDYFAR - MASM (Evgeny Sergeevich Dovgopolov)".

Processor status flags

CF
Yes
PF
Yes
AF
Yes
ZF
Yes
SF
Yes
TF
No
IF
No
DF
No
OF
?