Whether a string is a title-case string
A program that checks whether a string matches the title case format (every word starts with a capital letter).
Program source code
title .model small .stack 100h data segment public string db "The Quick Brown Fox$" strlen equ ($-string) msg_true db "True$" msg_false db "False$" 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 cx, strlen ; Copy the length of the string byte array into the cx register lea si, ds:[string] ; Load the address of the string variable into the ds:si register call CheckString ; Call the CheckString procedure jnz FalseMessage ; If ZF=0, jump to the FalseMessage label lea dx, ds:[msg_true] ; Load the address of the msg_true variable into the ds:dx register jmp Done ; Jump unconditionally to the Done label FalseMessage: lea dx, ds:[msg_false] ; Load the address of the msg_false variable into the ds:dx register Done: mov ah, 09h ; Copy the string output function number into ah 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 CheckString proc push ax ; Save the ax register value on the stack push si ; Save the si register value on the stack mov al, 1 ; Copy the value 1 into the al register (if al=1, the result is False) jmp CheckFirstLetter ; Jump unconditionally to the CheckFirstLetter label CheckLoop: cmp byte ptr[si-1], 20h ; Compare the value at si-1 with a space jne Skip ; If ZF=0, jump to the Skip label CheckFirstLetter: cmp byte ptr[si], 41h ; Compare the value in the si register with 'A' jb False ; If the value in si is below 'A', jump to the False label cmp byte ptr[si], 5Ah ; Compare the value in the si register with 'Z' ja False ; If the value in si is above 'Z', jump to the False label xor al, al ; Clear the al register (if al=0, the result is True) Skip: inc si ; Increment the si index by 1 loop CheckLoop ; Loop while the CX register is not equal to 0 test al, al ; Perform a logical comparison of the al register with itself False: pop si ; Pop the value from the stack into the si register pop ax ; Pop the value from the stack into the ax register ret ; Return from the procedure CheckString endp code ends end main
True
Example taken from the textbook "HANDYFAR - MASM (Evgeny Sergeevich Dovgopolov)".