Replacing spaces in a string with a specific character
A program that replaces all spaces in a string with a specific character.
Program source code
title .model small .stack 100h data segment public string db "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 mov cx, strlen ; Copy the value of the strlen variable into the cx register lea si, ds:[string] ; Load the address of the string variable into ds:si MainLoop: lodsb ; Load a byte from the source register si into the al register. SI++ cmp al, 20h ; Compare the value in the al register with a space 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: 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
Microsoft_Macro_Assembler
Example taken from the textbook "HANDYFAR - MASM (Evgeny Sergeevich Dovgopolov)".