ClubEnsayos.com - Ensayos de Calidad, Tareas y Monografias
Buscar

Assambler


Enviado por   •  2 de Septiembre de 2014  •  1.007 Palabras (5 Páginas)  •  226 Visitas

Página 1 de 5

External Modules

Most high-level languages (3rd-generation) allow the programmer to include object code compiled or assembled in other languages. A good example of this is Turbo Pascal's ability to use object code modules created from Turbo Assembler. There are various technical issues regarding the linkage of assembler to pascal code but, if the standard assembler directives are used there ought not to be too many glitches.

Of the multitude of items that need to be checked when linking assembler to pascal, the following are most important:

the assembler module must be created with the the functions to be exported indicated by a PUBLIC statement

the pascal program must contain an external declaration for the procedures to be imported

the pascal program must contain a {$L} include directive to include the object code into the program

when calling procedures with parameters, the parameters are shifted onto the stack from left to right - take note of this when writing the assembler code

return values from functions must be stored in the AX register

Although some languages (eg. C) allow the programmer to write modules in high-level language and link these to a main program in assembler, this is not possible with Turbo Pascal. It is only possible to write procedures in assembler and link these to pascal, which must contain the main program body.

In order to keep the following examples simple, all parameters and return values are assumed to be of type either byte or word. Turbo Pascal has some advanced features for linking to assembler modules but lots of these are very specific to Turbo Pascal. For further information, consult the Turbo Pascal Reference Manual.

Sample Program #17

{ program to illustrate simple linking to an ASM file from pascal }

program ExternalDeclarations;

procedure readsint; external; { define readsint as being in another module }

procedure writesint; external;{ define writesint as being in another module }

{$L ioasm.obj} { include ioasm module object code }

begin

readsint; { read in a value into AX }

writesint; { output the value in AX }

end.

Sample Program #18 - assembler part

; sample function to return a value

DOSSEG

.MODEL SMALL

.DATA

.CODE

PUBLIC samplefunc ; declare that samplefunc is to be used in other

; modules

samplefunc PROC ; stores a specific integer value into AX

mov ax,1234

ret

samplefunc ENDP

END

Sample Program #18 - pascal part

{ program to illustrate linking to a function in an ASM file from pascal }

program ExternalDeclarations;

function samplefunc : word; external;

{ define samplefunc as being in another module }

{$L sample18.obj} { include sample18 module object code }

begin

writeln ('The value is : ', samplefunc);

{ output return value from ASM module }

end.

Machine Code

Another option to programmers was to include machine code directly into the pascal program. By means of the INLINE command, the programmer could specify a string of machine code commands to be integrated with the compiled code at that point. This is not the option of choice since it means that the programmer has to convert the assembly language commands into machine code manually and enter the binary data into the pascal source file. This method is almost never used nowadays.

Inline assembler

The more recent versions of the Turbo Pascal compiler introduced a built-in assembler in the IDE. This means that a programmer can write parts of the pascal program directly in assembly language. The inline assembler, as it is called, can access all variables used in the program. Procedures can even be declared as strictly assembler, thereby eliminating the redundant startup and cleanup code that pascal might normally add.

Just

...

Descargar como (para miembros actualizados)  txt (6.2 Kb)  
Leer 4 páginas más »
Disponible sólo en Clubensayos.com