The FindChar function

The FindChar function searches for a character in a null-terminated string. If the character is found, a pointer to its first occurrence is returned. If the character is not found, the function returns 8000h and sets the CF flag = 1.

Parameters: AX: pointer to the string; BL: the character to search for.

Return value: AX: pointer to the character (CF=0) or 8000h (CF=1).

Flag state: The function affects the CF flag.

Program source code (Example 1)

An example program for the Intel 8086 assembler demonstrating the use of the FindChar function to search for a character in a string.

title Author: Evgeny Sergeevich Dovgopolov

.model small
.stack 100h

data segment public
    string db "Hello, World of Assembler!\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     bl, 'W'          ; Copy the value of the character 'W' into the bl register
        lea     ax, ds:[string]  ; Load the address of the string variable into the ds:ax register
        call    FindChar         ; Call the FindChar procedure (ax:string, bl:'W')
        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

World of Assembler!

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

Program source code (Example 2: all occurrences)

title Author: Evgeny Sergeevich Dovgopolov

.model small
.stack 100h

data segment public
    string db "Iris, like a heavenly messenger, unfolds its velvet petals.\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     bl, 'e'          ; Copy the value of the character 'e' into the bl register
        lea     ax, ds:[string]  ; Load the address of the string variable into the ds:ax register

  MainLoop:
        call    FindChar         ; Call the FindChar procedure (ax:string, bl:'e')
        jc      Done             ; If CF=1, jump to the label Done

        call    WriteString      ; Call the WriteString procedure (ax)
        call    PrintNewLine     ; Call the PrintNewLine procedure
        inc     ax               ; Increment the pointer by 1
        jmp     MainLoop         ; Perform an unconditional jump to the label MainLoop

    Done:
        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

e a heavenly messenger, unfolds its velvet petals.
eavenly messenger, unfolds its velvet petals.
enger, unfolds its velvet petals.
elvet petals.
etals.

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