MixedLanguageProgramming - Mixed Language Programming Mixed...

Info iconThis preview shows pages 1–2. Sign up to view the full content.

View Full Document Right Arrow Icon
Mixed Language Programming Beta Draft - Do not distribute © 2001, By Randall Hyde Page 1151 Mix ed Language Programming Chapter Twelve 12.1 Chapter Overview Most assembly language code doesn’ t appear in a stand-alone assembly language program. Instead, most assembly code is actually part of a library package that programs written in a high le v el language wind up calling. Although HLA mak es it really easy to write standalone assembly applications, at one point or another you’ ll probably w ant to call an HLA procedure from some code written in another language or you may w ant to call code written in another language from HLA. This chapter discusses the mechanisms for doing this in three languages: lo w-le v el assembly (i.e., MASM or Gas), C/C++, and Delphi/K ylix. The mechanisms for other languages are usually similar to one of these three, so the material in this chapter will still apply e v en if you’ re using some other high le v el language. 12.2 Mixing HLA and MASM/Gas Code in the Same Program It may seem kind of weird to mix MASM or Gas and HLA code in the same program. After all, the y’ re both assembly languages and almost an ything you can do with MASM or Gas can be done in HLA. So wh y bother trying to mix the tw o in the same program? W ell, there are three reasons: You’ve already got a lot of code written in MASM or Gas and you don’t want to convert it to HLA’s syntax. There are a few things MASM and Gas do that HLA cannot, and you happen to need to do one of those things. Someone else has written some MASM or Gas code and they want to be able to call code you’ve written using HLA. In this section, we’ll discuss two ways to merge MASM/Gas and HLA code in the same program: via in-line assembly code and through linking object files. 12.2.1 In-Line (MASM/Gas) Assembly Code in Your HLA Programs As you’ re probably a w are, the HLA compiler doesn’ t actually produce machine code directly from your HLA source fi les. Instead, it fi rst compiles the code to a MASM or Gas-compatible assembly language source fi le and then it calls MASM or Gas to assemble this code to object code. If you’ re interested in seeing the MASM or Gas output HLA produces, just edit the fi lename .ASM fi le that HLA creates after compiling your fi lename .HLA source fi le. The output assembly fi le isn’ t amazingly readable, b ut it is f airly easy to cor - relate the assembly output with the HLA source fi le. HLA pro vides tw o mechanisms that let you inject ra w MASM or Gas code directly into the output fi le it produces: the #ASM. . #END ASM sequence and the #EMIT statement. The #ASM. .#END ASM sequence copies all te xt between these tw o clauses directly to the assembly output fi le, e.g., #asm mov eax, 0 ;MASM/Gas syntax for MOV( 0, EAX ); add eax, ebx ; “ ADD( ebx, eax ); #endasm The #ASM. .#END ASM sequence is how you inject in-line (MASM or Gas) assembly code into your HLA programs. For the most port there is very little need to use this feature, but in a few instances it is valuable.
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Image of page 2
This is the end of the preview. Sign up to access the rest of the document.

This note was uploaded on 08/08/2011 for the course CS 101 taught by Professor Jitenderkumarchhabra during the Summer '11 term at National Institute of Technology, Calicut.

Page1 / 44

MixedLanguageProgramming - Mixed Language Programming Mixed...

This preview shows document pages 1 - 2. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online