FindCharEx function

The FindCharEx function searches for the first occurrence of a character in a string. The pointer to the string and the character are passed through the stack. It returns a pointer to the character (CF=0) or 8000h (CF=1). It keeps the pointer on the stack for nested calls. The function automatically aligns the stack to 4 bytes.

Parameters (stack): 1. Pointer to the string. 2. Character to search for.

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

Flag state: The function affects the CF flag.

Program source code (Example 1)

Intel 8086 assembly program example demonstrating the use of the FindCharEx function to search for a character in a string and print it to the console.

title Author: Evgeny Sergeevich Dovgopolov

.286C
.model small
.stack 100h

data segment public
    string db "Dovgopolov Evgeny Sergeevich!\0"
data ends

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

    main proc
        call    SetDataSegment  ; Call the SetDataSegment procedure

        push    'E'             ; Push the character 'E' onto the top of the stack
        pushs   ds:[string]     ; Push the address of the string variable onto the top of the stack
        call    FindCharEx      ; Call the FindCharEx(string, 'E') procedure
        call    WriteString     ; Call the WriteString(ax:string) procedure

        push    0               ; Push the byte return code onto the top of the stack
        call    ExitProcessEx   ; Call the ExitProcessEx(0) procedure
    main endp

code ends
end main

Evgeny Sergeevich!

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

Program source code (Example 2)

Intel 8086 assembly program example demonstrating the use of the FindCharEx function to search for a character in a string and print all occurrences in a loop.

title Author: Evgeny Sergeevich Dovgopolov

.286C
.model small
.stack 100h

data segment public
    string db "The iris, like a heavenly messenger, unfolds its velvety petals.\0"
data ends

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

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

        push    'i'             ; Push the character 'i' onto the top of the stack
        pushs   ds:[string]     ; Push the address of the string variable onto the top of the stack

  MainLoop:
        call    FindCharEx      ; Call the FindCharEx(string, 'i') procedure
        jc      Done            ; If CF=1, jump to the label Done

        call    WriteString     ; Call the WriteString(ax) procedure
        call    PrintNewLine    ; Call the PrintNewLine procedure
        jmp     MainLoop        ; Jump unconditionally to the label MainLoop

    Done:
        push    0               ; Push the byte return code onto the top of the stack
        call    ExitProcessEx   ; Call the ExitProcessEx(0) procedure
    main endp

code ends
end main

iris, like a heavenly messenger, unfolds its velvety petals.
is, like a heavenly messenger, unfolds its velvety petals.
ike a heavenly messenger, unfolds its velvety petals.
its velvety petals.

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