Inline assembly language BASM (англ.)

Inline assembly language BASM (англ.)

 

CONTENTS

 

Chapter 1  BASM.DOC                1         Inline assembly and register

Inline assembly language . . . . 1         variables . . . . . . . . .  7

BASM . . . . . . . . . . . . . 1         Inline assembly, offsets, and

Inline syntax  . . . . . . . . 2         size overrides  . . . . . .  7

Opcodes  . . . . . . . . . . . 3       Using C structure members . .  7

String instructions  . . . . 5       Using jump instructions and

Prefixes . . . . . . . . . . 5       labels  . . . . . . . . . . .  8

Jump instructions  . . . . . 5     Interrupt functions . . . . . .  9

Assembly directives  . . . . 6     Using low-level practices . . . 10

Inline assembly references to

data and functions . . . . . . 6   Index                             13

 

TABLES

___________________________________________________________________________

1.1: Opcode mnemonics  . . . . . . 4   1.3: Jump instructions  . . . . . .6

1.2: String instructions . . . . . 5

 

 

ii

 

 

 

 

 

 

 

 

 

 

 

 

 

Online document

___________________________________________________________________________

 

 

 

BASM.DOC

 

 

This online file tells you how to use the Turbo C++

built-in inline assembler (BASM) to include assembly

language routines in your C and C++ programs without

any need for a separate assembler. Such assembly

language routines are called inline assembly, because

they are compiled right along with your C routines,

rather than being assembled separately, then linked

together with modules produced by the C compiler.

 

Of course, Turbo C++ also supports traditional mixed-

language programming in which your C program calls

assembly language routines (or vice-versa) that are

separately assembled by TASM (Turbo Assembler), sold

separately. In order to interface C and assembly

language, you must know how to write 80×86 assembly

language routines and how to define segments, data

constants, and so on. You also need to be familiar with

calling conventions (parameter passing sequences) in C

and assembly language, including the pascal parameter

passing sequence in C.

 

Inline assembly  =======================================================

language

Turbo C++ lets you write assembly language code right

inside your C and C++ programs. This is known as inline

assembly.

 

——————  If you don’t invoke TASM, Turbo C++ can assemble your

BASM  inline assembly instructions using the built-in

——————  assembler (BASM). This assembler can do everything TASM

can do with the following restrictions:

 

o It cannot use assembler macros

 

 

 

 

— 1 —

 

 

 

 

 

 

 

o It cannot handle 80386 or 80486 instructions

 

o It does not permit Ideal mode syntax

 

o It allows only a limited set of assembler directives

(see page 6)

 

 

——————  Of course, you also need to be familiar with the 80×86

Inline syntax  instruction set and architecture. Even though you’re

——————  not writing complete assembly language routines, you

still need to know how the instructions you’re using

work, how to use them, and how not to use them.

 

Having done all that, you need only use the keyword asm

to introduce an inline assembly language instruction.

The format is

 

asm  opcode  operands ; or newline

 

where

 

o opcode is a valid 80×86 instruction (Table 1.0 lists

all allowable opcodes).

 

o operands contains the operand(s) acceptable to the

opcode, and can reference C constants, variables, and

labels.

 

o ; or newline is a semicolon or a new line, either of

which signals the end of the asm statement.

 

A new asm statement can be placed on the same line,

following a semicolon, but no asm statement can

continue to the next line.

 

To include a number of asm statements, surround them

with braces:

 

The initial brace   asm {

must appear on the      pop ax; pop ds

same line as the      iret

asm keyword.   }

 

Semicolons are not used to start comments (as they are

in TASM). When commenting asm statements, use C-style

comments, like this:

 

 

 

 

— 2 —

 

 

 

 

 

 

 

asm mov ax,ds;               /* This comment is OK */

asm {pop ax; pop ds; iret;}  /* This

Комментарии к записи Inline assembly language BASM (англ.) отключены

Рубрика: Программирование

Обсуждение закрыто.