BBS: Inland Empire Archive Date: 09-03-92 (21:14) Number: 314 From: MATT HART Refer#: NONE To: BRETT EMERY Recvd: NO Subj: Assembly w/QB Conf: (2) Quik_Bas
BE> crash. Could someone tellme which registers QB relys on, and QB expects the direction flag to be reset (CLD instruction). If you change DS, PUSH and POP it. It needs to be the same as when you called the routine. You should just about NEVER change the CS register. If you are going to do it anyway, save and restore it. But you really shouldn't change it. The same goes with the BP and SP registers. If you need them, put them into a variable or another register first and use the data there. MASM includes compiler directives (or macros or whatever USES is) to make saving the registers easy. Here's one of my sample ASM files. Improve it by passing parameter BYVAL (by value) rather than by reference, and do a word move rather than a byte move, moving a single byte first if the NumBytes parameter isn't even ( shift CX right 1, look at the carry flag, jump to a single byte move, then continue). DS comes in as QB's Dgroup. BP comes in with the stack QB pushed before jumping (4 bytes for QB's return address, and 2 bytes or so for each parameter - they are usually near address' into DS for the value of the parameter). ;MEMCOPY.ASM ; ;Call MemCopy (FromSegment, FromAddress, ToSegment, ToAddress, NumBytes) ; ;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