Inserting a space when an uppercase character follows a lowercase one

A program for processing camelCase strings: inserting a space when an uppercase letter follows a lowercase one.

Program source code

title Author: Evgeny Sergeevich Dovgopolov

.model small
.stack 100h

data segment public
    string db  "TheQuickBrownFox$"
    strlen equ ($-string)
    newstr db  strlen+4 dup(24h)
data ends

code segment public
    assume ds:data, cs:code

    main proc
        mov     ax, seg data         ; Get the data segment address and store it in ax
        mov     ds, ax               ; Pass the data segment address from ax to ds
        mov     es, ax               ; Pass the data segment address from ax to es

        mov     cx, strlen           ; Copy the length of the string byte array into the cx register
        lea     di, es:[newstr]      ; Load the address of the newstr variable into es:di
        lea     si, ds:[string]      ; Load the address of the string variable into ds:si
        call    ChangeString         ; Call the ChangeString procedure

        mov     ah, 09h              ; Copy the string output function number into ah
        lea     dx, ds:[newstr]      ; Load the address of the newstr variable into ds:dx
        int     21h                  ; Call the interrupt

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

    ChangeString proc
        push    ax                   ; Save the ax register value on the stack
        push    cx                   ; Save the cx register value on the stack
        push    si                   ; Save the si register value on the stack
        push    di                   ; Save the di register value on the stack

        jmp     Continue             ; Jump unconditionally to the Continue label

    CheckStringLoop:
        cmp     byte ptr[si], 41h    ; Compare the value in the si register with 'A'
        jb      Continue             ; If the value in si is below 'A', jump to Continue

        cmp     byte ptr[si], 5Ah    ; Compare the value in the si register with 'Z'
        ja      Continue             ; If the value in si is above 'Z', jump to Continue

        cmp     byte ptr[si-1], 61h  ; Compare the value in the si-1 register with 'a'
        jb      Continue             ; If the value in si-1 is below 'a', jump to Continue

        cmp     byte ptr[si-1], 7Ah  ; Compare the value in the si-1 register with 'z'
        ja      Continue             ; If the value in si-1 is above 'z', jump to Continue

        mov     byte ptr[di], 20h    ; Copy the space character value into the di register

        mov     al, byte ptr[si]     ; Copy the value in the si register into the al register
        mov     byte ptr[di+1], al   ; Copy the al register value into di+1

        inc     si                   ; Increment the si index by 1
        add     di, 2                ; Increment the di index by 2
        loop    CheckStringLoop      ; Loop while the CX register is not 0

    Continue:
        movsb                        ; Copy the value from ds:si into es:di. SI++, DI++
        loop    CheckStringLoop      ; Loop while the CX register is not 0

        pop     di                   ; Pop the value from the stack into the di register
        pop     si                   ; Pop the value from the stack into the si register
        pop     cx                   ; Pop the value from the stack into the cx register
        pop     ax                   ; Pop the value from the stack into the ax register
        ret                          ; Return from the procedure
    ChangeString endp

code ends
end main

The Quick Brown Fox

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