Help on interrupts.

 BBS: Inland Empire Archive
Date: 02-03-93 (13:00)             Number: 339
From: MARK GRAHAM                  Refer#: NONE
  To: IAN MACLENNAN                 Recvd: NO  
Subj: Help on interrupts.            Conf: (2) Quik_Bas
 On 02-01-93 Ian Maclennan wrote to All...
 IM>         I am looking for help on using certain interrupts with
 IM> Quickbasic 4.5.
 IM>  I can use some, but I seem to be unable to acess ones that use such
 IM> registers as AH, BH, AL etc.
 IM> This is really troubleing me as I am unable to use many interrupts.
 [...]

    No prob. ALL the standard registers (AX, BX, CX, DX) of the 80x86
    series are 16 bits (an integer to QB) broken into high byte (AH,
    BH, CH, DH) and low byte (AL, BL, CL, DL). The segment registers
    (CS, SS, DS, ES), index registers (SI, DI), and alternate stack
    pointer (BP) are also 16 bits, but because they are used for
    indexing, there is no reason to break them into smaller chunks.

    When calling interrupts from QB, a data structure is created from
    which the registers are loaded immediately before the interrupt is
    called, and to which the registers are saved immediately after
    execution of the interrupt.

    QB has TWO different interrupt calls, and each has its own data
    structure (these are in the include file QB.BI, by the way). The
    routine INTERRUPT loads and saves the registers AX, BX, CX, DX,
    BP, SI, DI, and flags. This data structure is called RegType. The
    INTERRUPTX routine loads and saves all the registers that
    INTERRUPT does, plus DS and ES, and should be used only when DS or
    ES need to point at some data structure. This data structure is
    call RegTypeX.

    Now, to your question, the registers AH and AL map to the high and
    low bytes of the AX variable. The confusing part is that QB
    insists that all two-byte integers are signed (positive and
    negative), so if bit 7 of AH is set, the number is negative. As
    for loading the registers, the hex prefix, &H, works nicely, and
    avoids the effort of sign conversion. So, if you wanted a function
    named Foo that loaded AH with 23 hex and AL with 45 hex, executed
    interrupt 10 hex, and returned the integer -1 if and only if CL is
    22 hex on return from the interrupt and zero otherwise, you could
    do the following:

FUNCTION Foo%()
    DIM regs AS RegType 'declare the data structure the 80x86
                        'registers will be loaded from and saved to

    regs.ax = &H2345    'Load hex 23 into AH and hex 45 into AL

    INTERRUPT &H10, regs, regs
    'the first is the structure from which the registers are loaded
    'the second is the structure to which the registers are are saved
    'they can often be the same structure

    Foo% = ((regs.cx AND 255) = &H22)
    'Isolate CL by setting all bits in CH to 0,
    'then testing if CX = 22 hex

END FUNCTION 'all done, so return


... OFFLINE 1.38

--- GEcho 1.00/beta+
 * Origin: The Extinguisher BBS, (916)334-4470 North Highlands, CA (1:203/540)
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