[ Usenet FAQs | Search | Web FAQs | Documents | RFC Index ]
    Search the FAQ Archives

Single Page

Top Document: x86 Assembly Language FAQ - Borland TASM
Previous Document: 2. Table of Contents
Next Document: 4. Inprise Borland TASM Information


3. TASM Ideal Mode


3.1  SUMMARY

TASM, Inpise's Borland Turbo Assembler, supports an alternative to MASM
emulation.  This is known as Ideal mode and provides several advantages
over MASM.  The key (questionable) disadvantage, of course, is that MASM
style assemblers cannot assemble Ideal mode programs.

3.2  MEMORY CONTENTS

Square brackets are used consistently to refer to memory contents.
Notice that size qualifiers are not necessary when TASM has enough
information by context to figure out the data size involved.  Here are
some examples without segment details:

    ByteVal db ?        ; "ByteVal" is name of byte variable
    mov ax, bx          ; OK:  Move value of BX to AX
    mov ax, [bx]        ; OK:  Move word at address BX to AX.  Size of
                        ; destination is used to generate proper object
                        ; code
    mov ax, [word bx]   ; OK:  Same as above with unnecessary size
                        ; qualifier
    mov ax, [word ptr bx]
                        ; OK:  Same as above with unnecessary size
                        ; qualifier and redundant pointer prefix
    mov al, [bx]        ; OK:  Move byte at address BX to AL.  Size of
                        ; destination is used to generate proper object
                        ; code
     mov [bx], al       ; OK:  Move AL to location BX
    mov ByteVal, al     ; Warning: "ByteVal" needs brackets
    mov [ByteVal], al   ; OK:  Move AL to memory location named
                        ;  "ByteVal"
    mov [ByteVal], ax   ; Error: unmatched operands
    mov al, [bx + 2]    ; OK:  Move byte from memory location BX + 2 to
                        ; AL
    mov al, bx[2]       ; Error: indexes must occur with "+" as above
    mov bx, Offset ByteVal
                        ; OK: Offset statement does not use brackets
    mov bx, Offset [ByteVal]
                        ; Error:  offset cannot be taken of the
                        ;  contents of memory
    lea bx, [ByteVal]   ; OK:  Load effective address of "ByteVal"
    lea bx, ByteVal     ; Error:  brackets required
    mov ax, 01234h      ; OK:  Move constant word to AX
    mov [bx], 012h      ; Warning: size qualifier needed to determine
                        ; whether to populate byte or word
    mov [byte bx], 012h ; OK:  constant 012h is moved to byte at
                        ;  address BX
    mov [word bx], 012h ; OK:  constant 012h is moved to word at
                        ;  address BX

STRUCTURE REFERENCES

Ideal mode handles structured records beautifully.  When referring to
structure members the dot operator is used.  The name to the left of the
dot is always the address of a structure and the name to right is always
a structure member.  Ideal mode permits member names to be duplicated in
different structures.  Here is a simple example, again without segment
details:

    Struc PosType
        Row     dw  ?
        Col     dw  ?
    Ends PosType

    Union PosValType
        Pos     PosType ?
        Val     dd      ?
    Ends PosValType

    Point   PosValType ?

    mov [Point.Pos.Row], bx     ; OK:  Move BX to Row component of Point
    mov [Point.Pos.Row], bl     ; Error:  mismatched operands

INDIRECTION

Ideal mode enforces type-size checking even with indirect references.
Using the above structure, here is how indirection is handled.  BX is
assumed to point to an instance of PosValType in memory.  Indirection is
used frequently when pointers are passed to procedures.

    mov [(PosValType bx).Pos.Row], ax
                        ; OK: Move AX to Row component of PosValType
                        ;  instance pointed to by BX
    mov [bx + PosValType.Pos.Row], ax
                        ; OK: same as above
    mov [bx + PosValType.Pos.Row], al
                        ; Error:  mismatched operands

SEGMENT GROUPS

The Offset operator always evaluates the offset of a data instance
relative to its group, not its segment.  This allows Offset to be used
without qualifying each reference with the appropriate group name.
Labels in a segment could be used to determine segment offsets if
needed.

RESOURCES

Books and files which will be of interest to programmers wishing to know
more about the Ideal mode of Borland's TASM assembler include the
following:

    Turbo Assembler User's Guide / Borland International.
    -------------------------------------------------------------------
    Naturally, this is the definitive text on Ideal mode.  Its focus is
    strictly on using TASM; it does not cover assembly language or the
    x86 instruction set.  Exasperatingly, the examples in the book all
    use MASM emulation mode, and only one of the four complete program
    examples included with TASM (at least version 3.1) uses Ideal mode.
    The example that does use Ideal mode is a very flexible WHEREIS
    program.  Studying this 13 file example should be sufficient for
    anyone wishing to understand Ideal mode.
    
    Mastering Turbo Assembler / Tom Swan.
    Indianapolis, IN:  Hayden Books, c 1989.
    ------------------------------------------------------------------
    This book is not just another Microsoft Assembler book reprinted
    with a Turbo Assembler cover.  Swan uses and promotes Ideal mode
    throughout.  This is a great beginning text for programmers who are
    still hassling with the ubiquitous non-reentrant interrupt handler
    known as DOS.  It includes an overview of the x86 instruction set.
    
    SKEL32.ZIP / Bill Magaletta.
    Obtainable by ftp at ftp://hobbes.nmsu.edu/os2/32bit/ as well as
    ftp-os2.cdrom.com and CompuServe
    ------------------------------------------------------------------
    This is a standalone 32 bit OS/2 Ideal mode program, the simplicity
    of which will make converts of DOS programmers dealing with
    interrupts and segments.  It includes an overview of the initial
    register states of DOS and OS/2 programs.  This example illustrates
    the fact that TASM for DOS can be used to produce object files for
    OS/2.

Contributor: Kurt Jung, kwjung@vela.acs.oakland.edu
Last changed: 17 Jan 95



Top Document: x86 Assembly Language FAQ - Borland TASM
Previous Document: 2. Table of Contents
Next Document: 4. Inprise Borland TASM Information

Single Page


[ Usenet FAQs | Search | Web FAQs | Documents | RFC Index ]

Send corrections/additions to the FAQ Maintainer:
raymoon@moonware.dgsys.com

Last Update October 14 2008 @ 00:10 AM

© 2008 FAQS.ORG. All rights reserved.