$ASM directive
Purpose: The $ASM directive allows
inline assembly instructions to be used with BCX. An $ASM directive must be placed before and after the
assembly statements.
Syntax: $ASM /** Assembly statements go here */ $ASM |
Intel Assembly Language Syntax Example:
The following example is a mixed code demo constructed to show
the use of the $ASM directive with BCX using
Intel assembly language syntax, that is, opcode, destination,
source.
DIMstr1$DIMstr2$ str1$="123456789"str2$=AsmLeft$(str1$,3)=AsmMid$(str1$,4,3)=AsmMid$(str1$,4)=AsmRight$(str1$,3)FUNCTIONSubStr%(SrcStrASLPSTR, SrcStrLen%, StartPosn%, DestStrASLPSTR, DestStrLen%)$ASMnop nop nop ;save used registers except for eax:edx push ebx push ecx push edi push esi ;load the32-bit registers from the stack mov esi,dwordPTR[ebp+8];SrcStr mov edx,dwordPTR[ebp+12];SrcLen mov eax,dwordPTR[ebp+16];StartPosn mov edi,dwordPTR[ebp+20];DestStr mov ecx,dwordPTR[ebp+24];DestLen ;check for zero-length Destination string jecxz NoGood ;compensate StartPosn for0based count dec eax ;check for negative offset of StartPosn cmp eax,0jl NoGood ;point esi to start of SrcStr add esi, eax ;and subtract StartPosn from SrcLen sub edx, eax ;check if offset is past end of SrcStr cmp edx,0jle NoGood ;move substring of esi into edi rep movsb ;return this to indicate function worked mov eax, edi jmp ReturnAX NoGood: mov eax,-1ReturnAX: pop esi pop edi pop ecx pop ebx pop ebp ret$ASMFUNCTION=0ENDFUNCTION'Left$ equivalentFUNCTIONAsmLeft$(fnstr1$, fnint1%)DIMRAWstartp%=1DIMRAWretstr$*fnint1%+256SubStr(fnstr1$,LEN(fnstr1$), startp%, retstr$, fnint1%)retstr[fnint1]=0FUNCTION=retstr$ENDFUNCTION'MID$ equivalentFUNCTIONAsmMid$OPTIONAL(fnstr1$, fnint1%, fnint2%=0)DIMRAWstartp%=fnint1%DIMRAWlenfnstr1%=LEN(fnstr1$)DIMRAWretstr$*fnint2%+256IFfnint2%=0THENfnint2%=lenfnstr1%-startp%+1ENDIFSubStr(fnstr1$, lenfnstr1%, startp%, retstr$, fnint2%)retstr[fnint2]=0FUNCTION=retstr$ENDFUNCTION'RIGHT$ equivalentFUNCTIONAsmRight$(fnstr1$, fnint1%)DIMRAWlenfnstr1%=LEN(fnstr1$)DIMRAWstartp%=lenfnstr1%-fnint1%+1DIMRAWretstr$*fnint1%+256SubStr(fnstr1$, lenfnstr1%, startp%, retstr$, fnint1%)retstr[fnint1]=0FUNCTION=retstr$ENDFUNCTION