BBS: Inland Empire Archive Date: 07-06-92 (20:13) Number: 208 From: MATT HART Refer#: NONE To: RICHARD VANNOY Recvd: NO Subj: Dos Programmer'S Ref(Que) Conf: (2) Quik_Bas
RV> I'm working on how to get assembler code into QB/PDS. RV> Comments and advice appreciated. Here's a full assembler routine for QB that compiles under MASM 5.x. Also under MASM 6.0 by using C:\>ml /c memcopy or by using the MASM pre-processor (which slows everything down). ' In .BAS program: DEFINT A-Z CALL MemCopy (FSeg, FAdd, TSeg, TAdd, NumBytes) ' ------------- Actually this routine can be improved quite easily. I wrote it before I started using the BYVAL keyword, which passes parameters by value rather than by reference. So the assembler commands: MOV BX,FAdr ;FAdr pointer MOV SI,[BX] ;Put into SI register can be accomplished with: MOV SI,FAdr a single move and a much better time savings. You cannot pass a value BACK to the basic program when all parameters are passed by value, but you can easily make all non- changing parameters by value and the one you need to change passed by reference: CALL Routine(BYVAL Param1, Ecode) where Param1 is passed by value and Ecode by reference, so it can receive something coming back. Also, if NumBytes was NOT even, you could do a single move byte and then use MOVSW which moves two bytes at a time, much faster than MOVSB. After compiling, you have MEMCOPY.OBJ. Just put the CALL into your program wherever, and link with it: LINK Myprog + Memcopy,,,brt71enr; This is VERY useful - copy blocks of memory up to 64K in size from one area to another. For greater than 32767, use negative numbers with: NumBytes = CINT( 35&*1024& - 64&*1024& ) With this, you can do fixed length arrays (strings, TYPE, numeric) deletes and inserts. Copy multiple screens to integer arrays. All this stuff is practically instantaneous. ;MEMCOPY.ASM ;All parameters must be integers .Model Medium,BASIC .Code MemCopy PROC USES DS ES SI DI, FSeg:Ptr, FAdr:Ptr, TSeg:Ptr, TAdr:Ptr, \ NumBytes:Ptr CLD ;Forward move MOV BX,FAdr ;FAdr pointer MOV SI,[BX] ;Put into SI register MOV BX,TSeg ;TSeg pointer MOV ES,[BX] ;Put into ES register MOV BX,TAdr ;TAdr pointer MOV DI,[BX] ;Put into DI register MOV BX,NumBytes ;NumBytes pointer MOV CX,[BX] ;Put into CX register MOV BX,FSeg ;FSeg pointer PUSH DS ;Save DS to restore after move MOV DS,[BX] ;Put FSeg into DS register REP Movsb ;Move DS,SI to ES,DI POP DS ;Restore DS RET ;return to BASIC MemCopy ENDP END ~~ --- * Origin: Midnight Micro! V.32/REL (918)451-3306 (1:170/600)
Books at Amazon:
Back to BASIC: The History, Corruption, and Future of the Language
Hackers: Heroes of the Computer Revolution (including Tiny BASIC)
Go to: The Story of the Math Majors, Bridge Players, Engineers, Chess Wizards, Scientists and Iconoclasts who were the Hero Programmers of the Software Revolution
The Advent of the Algorithm: The Idea that Rules the World
Moths in the Machine: The Power and Perils of Programming
Mastering Visual Basic .NET