IsHexadecimalEx function

The IsHexadecimalEx function checks whether the character passed through the stack is a valid hexadecimal character (0-9, A-F, a-f). The function automatically aligns the stack to 2 bytes.

Parameters (stack): 1. Character to check.

Return value: ZF = 1 if the character is valid in HEX; ZF = 0 otherwise.

Flag state: The function affects all processor flags.

Program source code

Intel 8086 assembly program example demonstrating the use of the IsHexadecimalEx function to check whether a character from the stack is valid in the hexadecimal system.

title Author: Evgeny Sergeevich Dovgopolov

.286C
.model small
.stack 100h

data segment public
    msg_true  db "TRUE\0"
    msg_false db "FALSE\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
        call    IsHexadecimalEx  ; Call the IsHexadecimalEx('E') procedure

        jne     @False           ; If ZF=0, jump to the label @False

    @True:
        pushs   ds:[msg_true]    ; Push the address of the msg_true variable onto the top of the stack
        jmp     @Done            ; Jump unconditionally to the label @Done

    @False:
        pushs   ds:[msg_false]   ; Push the address of the msg_false variable onto the top of the stack

    @Done:
        call    WriteStringEx    ; Call the WriteStringEx(value from the stack) 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

TRUE

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