Removing a specific character from a given string
A program that removes a specific character from a given string. It returns the updated string. In this example we remove the character 'o'.
Program source code
title .model small .stack 100h data segment public string db "Microsoft Macro Assembler" strlen equ ($-string) newstr db strlen 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 value of the strlen variable into the cx register lea di, es:[newstr] ; Load the address of the newstr variable into the destination register es:di lea si, ds:[string] ; Load the address of the string variable into the source register ds:si MainLoop: lodsb ; Load a byte from the source register si into the al register cmp al, 6Fh ; Compare the value in the al register with the character 'o' je Skip ; If ZF=1, jump to the Skip label stosb ; Store the byte from the al register in the destination register di Skip: loop MainLoop ; Loop while CX≠0 mov ah, 09h ; Copy the string output function number into ah lea dx, ds:[newstr] ; Load the address of the newstr 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
Micrsft Macr Assembler
Example taken from the textbook "HANDYFAR - MASM (Evgeny Sergeevich Dovgopolov)".