Same rightmost digit

A program that checks whether two or more of three integers have the same rightmost digit.

Program source code

title Author: Evgeny Sergeevich Dovgopolov

.286C
.model small
.stack 100h

data segment public
    fmtout db "Result: %s\n\0"
data ends

code segment public                     ; Start of the code segment
    assume  ds:data, cs:code
    include Handyfar.inc                ; Include the file with functions

    main proc                           ; Start of the main procedure
        call    SetDataSegment          ; Call the SetDataSegment procedure

        push    11                      ; Save the value 11 on the stack
        push    21                      ; Save the value 21 on the stack
        push    31                      ; Save the value 31 on the stack
        call    Calculate               ; Call the Calculate procedure (return value in ax)

        push    ax                      ; 2nd: save the ax register value on the stack
        lea     ax, ds:[fmtout]         ; 1st: load the address of the fmtout format string into ax
        call    PrintFormatString       ; Call the PrintFormatString procedure
        add     sp, 2                   ; Align the stack

        push    13                      ; Save the value 13 on the stack
        push    22                      ; Save the value 22 on the stack
        push    31                      ; Save the value 31 on the stack
        call    Calculate               ; Call the Calculate procedure (return value in ax)

        push    ax                      ; 2nd: save the ax register value on the stack
        lea     ax, ds:[fmtout]         ; 1st: load the address of the fmtout format string into ax
        call    PrintFormatString       ; Call the PrintFormatString procedure
        add     sp, 2                   ; Align the stack

        xor     al, al                  ; Clear the al register
        call    ExitProcess             ; Call the ExitProcess procedure
    main endp                           ; End of the main procedure

    Calculate proc                      ; Start of the Calculate procedure
        push    bp                      ; Save the bp register value on the stack
        mov     bp, sp                  ; Copy the sp register value into bp
        sub     sp, 2                   ; Create a 2-byte local stack area
        pushf                           ; Save the FLAGS register value on the stack

        push    bx                      ; Save the bx register value on the stack
        push    dx                      ; Save the value of the dx register on the stack

    data segment
        msg_true  db "True\0"
        msg_false db "False\0"
    data ends

        mov     bx, 10                  ; Copy the number 10 into the bx register

        mov     ax, word ptr ss:[bp+4]  ; Copy the first parameter at [bp+4] on the stack into ax
        cwd                             ; Perform sign extension of the dx register.
        idiv    bx                      ; Divide the value in ax by the value in bx
        mov     byte ptr ss:[bp-2], dl  ; Save the remainder in the local stack at [bp-2]

        mov     ax, word ptr ss:[bp+6]  ; Copy the second parameter at [bp+6] on the stack into ax
        cwd                             ; Perform sign extension of the dx register.
        idiv    bx                      ; Divide the value in ax by the value in bx
        mov     byte ptr ss:[bp-1], dl  ; Save the remainder in the local stack at [bp-1]

        mov     ax, word ptr ss:[bp+8]  ; Copy the third parameter at [bp+8] on the stack into ax
        cwd                             ; Perform sign extension of the dx register.
        idiv    bx                      ; Divide the value in ax by the value in bx

        mov     al, byte ptr ss:[bp-2]  ; Copy the value at [bp-2] in the local stack into al
        cmp     al, byte ptr ss:[bp-1]  ; Compare al with the value in the local stack at [bp-1]
        jz      @True                   ; If ZF=1, jump to the @True label

        cmp     al, dl                  ; Compare al with the value in dl
        jz      @True                   ; If ZF=1, jump to the @True label

        cmp     byte ptr ss:[bp-1], dl  ; Compare the value in the local stack at [bp-1] with dl
        jz      @True                   ; If ZF=1, jump to the @True label

        lea     ax, ds:[msg_false]      ; Load the address of the msg_false variable into the ax register
        jmp     @Done                   ; Jump unconditionally to the @Done label

    @True:
        lea     ax, ds:[msg_true]       ; Load the address of the msg_true variable into the ax register

    @Done:
        pop     dx                      ; Pop the value from the stack into the dx register
        pop     bx                      ; Pop the value from the stack into bx

        popf                            ; Pop the flags from the stack into the FLAGS register
        add     sp, 2                   ; Remove the created 2-byte local stack
        pop     bp                      ; Pop the value from the stack into bp
        ret     6                       ; Return from the procedure with stack alignment of 6 bytes
    Calculate endp                      ; End of the Calculate procedure

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

Result: True
Result: False

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