MGT Computer Solutions >>
Services >>
Custom Programming >>
Assembler >> Example PC Assembler Code
This example Microsoft Macro-Assembler v.5.1 program implements a function for validating byte data. The function can be declared within and called from a Microsoft 16-bit BASIC program.
; NotInRange -- for quick validation of stuff like ALPHA, ALPHANUMERIC, etc. NotInRange PROC ; Proc NotInRange USES DS ES DI SI, OffsetWW:Word Target3:Word Search3:Word ; masm 6 ; DECLARE FUNCTION NotInRange% (offset%, WhatToSearch$, LowEnd%, HiEnd%) ' DECLARATION ; IF NotInRange%(1%, UCASE$(A$), 65, 90) < 2 THEN EXIT FUNCTION ' EXAMPLE test for ALPHA ; Returns 0 if each byte in WhatToSearch$ is "within range", otherwise ; Returns the position of the first byte with an "out-of-range" value Offset4 EQU <[BP+12]> ; NotInRange parm1 - the place to start search Target4 EQU <[BP+10]> ; NotInRange parm2 - the string to search LowEnd4 EQU <[BP+8]> ; NotInRange parm3 - the low end of the set of char values to accept HiEnd4 EQU <[BP+6]> ; NotInRange parm4 - the high end of the set of char values to accept push bp ; entry sequence - saved old BP mov bp,sp ; set stack framepointer push ds ; save ds and friends push es push si mov si,Offset4 ; put address of parameter in si mov bx,[si] ; offset value to bx dec bx cmp bx,0 ; is the user's offset bogus? jge L003 ; if not bogus, avoid the following debacle jmp B$ERR_FC ; trust to BASIC's error handler L003: mov si,LowEnd4 ; put address of parm 3 in si mov dl,[si] ; offset value to dl mov si,HiEnd4 ; put address of parm 4 in si mov dh,[si] ; offset value to dh mov si,Target4 ; put string descriptor address in si mov cx,[si] ; put LEN(WorkArg$) in cx. mov si,[si+2] ; get string offset in si TestForWithinRange: cmp bx,cx ; are we at end of string jae OutsideRange ; if so, jump mov al,ds:[si+bx] ; load the character cmp al,dl jb OutsideRange cmp al,dh ja OutsideRange inc bx jmp TestForWithinRange OutsideRange: inc bx ; adjust mov ax,bx ; returned offset goes into ax pop si ; restore si pop es ; restore es pop ds ; restore ds pop bp ; restore bp ret 8 ; go back (skip 4 words on stack) NotInRange ENDP