Replacing vowels in a string with an underscore
A program that finds vowels in a string and replaces them with an underscore.
Program source code
title .model small .stack 100h data segment public string db "Microsoft Macro Assembler" strlen equ ($-string) vowels db "aeiou" vowlen equ ($-vowels) 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 value of the strlen variable into the cx register lea di, es:[vowels] ; Load the address of the vowels array into the es:di register lea si, ds:[string] ; Load the address of the string array into the ds:si register MainLoop: push cx ; Save the value of the cx register on the stack push di ; Save the value of the di register on the stack mov cx, vowlen ; Copy the value of the vowlen variable into the cx register lodsb ; Load a byte from the source register si into the al register. SI++ repnz scasb ; Scan the byte in the al register against the byte in the es:di register jne Skip ; If ZF=0, jump to the Skip label mov byte ptr[si-1], 5Fh ; Copy the value of the '_' character into si-1 Skip: pop di ; Pop the saved value from the stack into the di register pop cx ; Pop the saved value from the stack into the cx register loop MainLoop ; Loop while CX≠0 mov ah, 09h ; Copy the string output function number into ah lea dx, ds:[string] ; Load the address of the string variable into the ds:dx register 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 code ends end main
M_cr_s_ft M_cr_ Ass_mbl_r
Example taken from the textbook "HANDYFAR - MASM (Evgeny Sergeevich Dovgopolov)".