Interactive PowerBasic Forum

IT-Berater: Theo Gottwald (IT-Consultant) => Low Level Code Optimization => Low Level Code Optimization PB 10 => Topic started by: Theo Gottwald on September 27, 2025, 11:04:35 PM

Title: Restrict LONG Value between A and B
Post by: Theo Gottwald on September 27, 2025, 11:04:35 PM
Can be done in ASM without using JMP's.

P1 - LONG Value to check
P2 - Minimum Value (number)
P3 - Maximum Value (number)

Macro ARR_Between(P1, P2, P3)
    ! mov eax, P1            ; Load P1 value into EAX
    ! mov edx, P2            ; edx = minimum value (P2)
    ! cmp eax, edx           ; Compare with minimum
    ! cmovl eax, edx         ; If less than minimum, set to minimum
    ! mov edx, P3            ; edx = maximum value (P3)
    ! cmp eax, edx           ; Compare with maximum
    ! cmova eax, edx         ; If above maximum, set to maximum
    ! mov P1, eax            ; Store result back to P1
End Macro

Result: P1 will be between (including) P1 and P2.