TIP: Click on subject to list as thread! ANSI
echo: power_bas
to: ALL
from: DAVE NAVARRO
date: 1995-05-16 17:05:00
subject: Fast string array searchi

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)

SOURCE: echomail via exec-pc

Email questions or comments to sysop@ipingthereforeiam.com
All parts of this website painstakingly hand-crafted in the U.S.A.!
IPTIA BBS/MUD/Terminal/Game Server List, © 2025 IPTIA Consulting™.