Capitalizing the first letter of each word in a string
A program that capitalizes the first letter of each word in a given string. Words can be separated by multiple spaces. Note that the value of the bx register is not destroyed inside the loop in this program.
Program source code
title .model small .stack 100h data segment public string db "intel 8086. microsoft macro assembler$" strlen equ ($-string) 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 xor si, si ; Clear the si counter register mov cx, strlen ; Copy the value of the strlen variable into the cx register lea bx, ds:[string] ; Load the address of the string variable into the ds:bx register jmp ToUpper ; Jump unconditionally to the ToUpper label MainLoop: cmp byte ptr[bx+si-1], 20h ; Compare the value in bx at index si-1 with a space jne Skip ; If ZF=0, jump to the Skip label ToUpper: cmp byte ptr[bx+si], 61h ; Compare the value in the bx register at index si with 'a' jb Skip ; If the value is below 61h ('a'), then jump to the Skip label cmp byte ptr[bx+si], 7Ah ; Compare the value in the bx register at index si with 'z' ja Skip ; If the value is above 7Ah ('z'), then jump to the Skip label and byte ptr[bx+si], 0DFh ; Convert the value to upper case by clearing bit 5 Skip: inc si ; Increment the si index register by 1 loop MainLoop ; Loop while the value in the CX register is not 0 mov ah, 09h ; Copy the string output function number into ah mov dx, bx ; Copy the bx register value into the dx register int 21h ; Call the interrupt mov ax, 4C00h ; Copy the exit function value into ah and the value into al int 21h ; Call the interrupt main endp code ends end main
Intel 8086. Microsoft Macro Assembler
Example taken from the textbook "HANDYFAR - MASM (Evgeny Sergeevich Dovgopolov)".