Assembly w/QB

 BBS: Inland Empire Archive
Date: 09-11-92 (14:54)             Number: 315
From: TONY ELLIOTT                 Refer#: NONE
  To: BRETT EMERY                   Recvd: NO  
Subj: Assembly w/QB                  Conf: (2) Quik_Bas
Brett,

BE>I think when QB starts the code, DS is set to the segment
  >of the variables passed.  Now if "uses DS" is used, wont
  >that disable passing variables???

There are lots of ways to pass arguments to assembly routines. If the
numeric argument dos not need to be modified by the routine, you can
pass it BYVAL .. that is, the VALUE of the argument is pushed on the
stack .. not a pointer (which is the BASIC default). For example:

DECLARE FUNCTION AddOne% (BYVAL Agr1%)

B% = 1
PRINT AddOne%(B%)

;---Asm code
.Model Medium, Basic
.Code

AddOne proc, StartingValue:Word

        ;If the parameter was passed BYVAL, we can to it this way:

        mov     ax, StartingValue       ;Move value from stack right
        inc     ax                      ; into ax and increment it.
        ret                             ;That was easy, wasn't it?

        ;If passed BYREF (which is BASIC's default), another step would
        ;be required:

        mov     bx,StartingValue        ;Pointer to argument into bx
        mov     ax,[bx]                 ;Now, move value into ax
        inc     ax
        ret

AddOne endp
end

What happens if DS is being used for something else? Well, remember
that SS -always- points to DGroup (that is where the stack is
located). You can put an SS: override on your data addressing,
or move SS into ES (via one of the other registers) and use an ES:
override. A segment override only ads 1 byte to the instruction and 2
clocks. Sometimes just what the doctor ordered.

Tony
___
 X 1st 1.01b #1030s X Beware of programmers that carry screwdrivers

--- Maximus 2.01wb
 * Origin: Oakland BBS (1:133/706)
Outer Court
Echo Basic Postings

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