The AAS instruction

Adjusting the AL register after subtraction.

The AAS instruction format

InstructionDescription
AASAdjusting the AL register after subtraction

Adjusts the result of subtracting two unpacked BCD values to create an unpacked BCD result. The al register is the implied source and destination operand for this instruction. The aas instruction is useful only when it follows a sub instruction that subtracts one unpacked BCD value from another and stores a byte result in the al register. The aas instruction then adjusts the contents of the al register so that it contains the correct 1-digit unpacked BCD result.

If the subtraction produced a decimal borrow, the ah register is decremented by 1 and the CF and AF flags are set. If no decimal borrow occurred, the CF and AF flags are cleared and the ah register is left unchanged. In either case, the al register is left with its four high bits set to 0.

First example: 14 - 5

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     ax, 0104h  ; Copy the unpacked value 14 into the ax register
        sub     al, 5      ; Subtract the value 5 from the al register
        aas                ; Adjust the contents of the al register

        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)".

Second example: 53 - 6 - 9 with screen output

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     ax, 0503h  ; Copy the unpacked value 53 into the ax register
        sub     al, 6      ; Subtract the value 6 from the al register
        aas                ; Adjust the contents of the al register

        sub     al, 9      ; Subtract the value 9 from the al register
        aas                ; Adjust the contents of the al register

        mov     bx, ax     ; Save the value of the ax register in the bx register
        or      bx, 3030h  ; Convert the value in the bx register into an ASCII number

        mov     ah, 02h    ; Copy the console output function number into ah
        mov     dl, bh     ; Copy the ASCII number from the bh register into the dl register
        int     21h        ; Call the interrupt
        mov     dl, bl     ; Copy the ASCII number from the bl register into the dl register
        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
?
AF
Yes
ZF
?
SF
?
TF
No
IF
No
DF
No
OF
?