Fast ASM code for finding the first empty element of a string array:
DEFINT A-Z
DIM MyArray$(1:100)
FOR x = 1 TO 25
MyArray$(x) = STR$(x)
NEXT x
PRINT FirstElem(MyArray$(1)) 'should print 26
FUNCTION FirstElem(temp$) PUBLIC
! push DS ; save DS for PowerBASIC
! mov CX, -1 ; search 64k of string handles
! les DI, temp$ ; point ES:DI to first string handle
TestLoop:
! cmp Word Ptr ES:[DI], 0 ; is it a null handle?
! je Found ; yes, exit loop
! inc DI ; move to next
! inc DI ; handle in the array
! loop TestLoop ; keep looping
Found:
! not CX ; convert to positive value
! inc CX ; add one
! mov FUNCTION, CX ; return function result
! pop DS ; restore DS for PowerBASIC
END FUNCTION
---
* QMPro 1.53 * Alumnus of the Institute for the Sexually Gifted.
--- WILDMAIL!/WC v4.12
---------------
* Origin: Toast House * (314) 994-0312 * (1:100/560.0)
|