ReadStringEx function

The ReadStringEx function reads user input from the keyboard and stores it in a prepared null-terminated buffer. The buffer address is passed through the stack. The function automatically aligns the stack to 2 bytes.

Parameters (stack): 1. Pointer to the buffer.

Return value: The function does not return a value.

Flag state: The function does not modify the flags.

Program source code

Intel 8086 assembly program example demonstrating the use of the ReadStringEx function to input a string into a buffer whose address is passed through the stack.

title Author: Evgeny Sergeevich Dovgopolov

.286C
.model small
.stack 100h

data segment public
    askUser db "Enter your full name: \0"
    output  db "\nYour full name \0"
    buffer  db 255 dup(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

        pushs   ds:[askUser]    ; Push the address of variable string onto the stack
        call    WriteStringEx   ; Call procedure WriteStringEx(string)

        pushs   ds:[buffer]     ; Push the address of variable buffer onto the stack
        call    ReadStringEx    ; Call procedure ReadStringEx(buffer)

        pushs   ds:[output]     ; Push the address of variable output onto the stack
        call    WriteStringEx   ; Call procedure WriteStringEx(output)

        pushs   ds:[buffer]     ; Push the address of variable buffer onto the stack
        call    WriteStringEx   ; Call procedure WriteStringEx(buffer)

        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

Enter your full name: Evgeny Sergeevich Dovgopolov
Your full name Evgeny Sergeevich Dovgopolov

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