The StringReplaceChar function

The StringReplaceChar function replaces all occurrences of the specified character in a null-terminated string with another character.

Parameters: AX: pointer to the string; BL: the character to be replaced; BH: the character to replace it with.

Return value: The function does not return a value.

Flag state: The function does not modify the flags.

Program source code

An example program for the Intel 8086 assembler demonstrating the use of the StringReplaceChar function to replace characters in a string.

title Author: Evgeny Sergeevich Dovgopolov

.model small
.stack 100h

data segment public
    string db "Learning assembly language - it is fun!\0"
data ends

code segment public                ; Start of the code segment
    assume  ds:data, cs:code
    include Handyfar.inc           ; Include the file with functions

    main proc                      ; Start of the main procedure
        call    SetDataSegment     ; Call the SetDataSegment procedure

        mov     bh, '_'            ; Copy the underscore character value into the bh register
        mov     bl, ' '            ; Copy the space character value into the bl register
        lea     ax, ds:[string]    ; Load the address of the variable string into the ds:ax register
        call    StringReplaceChar  ; Call the StringReplaceChar procedure (ds:ax, bl:' ', bh:'_')
        call    WriteString        ; Call the WriteString procedure (ax)

        xor     al, al             ; Clear the al register
        call    ExitProcess        ; Call the ExitProcess procedure
    main endp                      ; End of the main procedure

code ends                          ; End of the code segment
end main	                       ; End of file. The main procedure is the entry point

Learning_assembly_language_-_it_is_fun!

Example taken from the textbook "HANDYFAR - MASM (Evgeny Sergeevich Dovgopolov)".