High Level Language Support Instructions in Assembly Language (original) (raw)


music

| OSdata.com: assembly language | | OSdata.com | | --------------------------------------------------------------------------------------------- | | ---------- |

high level language support

summary

This web page examines high level language support instructions in assembly language. Specific examples of instructions from various processors are used to illustrate the general nature of assembly language.

free computer programming text book project

Now building a [For those with high speed connections, the very large single file ](../../milo/milo.html>free emulator and assembly language proigramming lessons.

  • table of contents for assembly language section
  • assembly/high level language interface
  • high level language support
  • further reading: books on assembly language
  • related software
  • further reading: websites
  • assembly/high level language interface

    Because so many search requests are asking about how to interface between high level languages and assembly language, I have added this brief discussion.

    Unfortunately, I can only provide you with some general guidelines rather than specific details. You will need to do further research on your own. If your high level compiler allows you to see an assembly language representation of its output, you should be able to figure out the details on your own.

    Each processor has its own conventions on subroutine and function linkage. Each high level language also has its own conventions regarding subroutine and function linkage. Some operating systems add their own conventions to the mix. As these three sets of conventions are often at odds, you will need to do your own research to determine how any conflicts in conventions are resolved on your system (again, if your compiler produces an assembly language representation, you can use these listings and carefully crafted test code to determine your local rules).

    C treats all subroutines as functions. Unless otherwise declared, each function returns an integer (which is usually the default size of a word on the processor). Parameters are passed by value by pushing the data onto the stack in right to left order (based on the function declaration). Objects less than four bytes (such as boolean, integer, and character) are sign-extended to four bytes. C arrays are passed by pointer. Sometimes C will break the rule and instead pass a pointer for a large data item (such as C arrays), so you may want to examine sample object code to see how various large data structures are handled. Depending on the processor, C function results are returned on the top of the stack (typically the space for the function return value is allocated on the stack after all of the parameters have been passed) or in a register (usually the default scratch register for that processor). The calling routine is responsible for removal of parameters.

    Pascal has both subroutines and functions. For subroutines, there is no space allocated on the stack for a return value, while for functions the space for the return value is allocated on the stack after all of the parameters are passed. Parameters are pushed onto the stack in left to right order (based on the subroutine or function declaration). Parameters that are 32 bits or smaller are passed by value (the actual data is placed on the stack), while parameters that are greater than 32 bits are passed by reference (a pointer to the data is placed on the stack). Parameters of variable length are always passed by reference (a pointer) regardless of actual size (this applies in particular to pascal strings). If a data type is not an exact multiple of a byte (such as a bit string or set or certain kinds of ennumerated data), then the data element will be rounded up to the nearest byte, usually with zero padding in the high order bits (check your compiler output). Booleans are passed as a single byte (0 or 1), but boolean function results are returned as a pair of bytes with the boolean in the high byte. VARs are passed as four byte pointers. On some processors, data types that are not exact multiples of 16 or 32 bits are zero padded (high order bytes) to a 16 bit or 32 bit size (again, check your compiler output). The called routine is normally responsible for removal of parameters (other than a function return parameter).

    high level language support

    Many processors have instructions designed to support constructs common in high level languages. Ironically, a few high level language constructs have been based on specific hardware instructions on specific processors. One famous example is the computed GOTO (three possible branches based on whether the tested value is positive, zero, or negative), which is based on a hardware instruction in an early IBM processor (and if anyone can loan or give me a data book on the processor, I sure would appreciate it).

    Most modern processors have some kind of loop instructions. These are some variation on the theme of testing for a condition and/or making a count with a short branch back to complete a loop if the exit condition fails.

    Many modern processors have some kind of hardware support for temporary data storage (for the temporary variables used in subroutines and functions), combining special hardware instructions with argument and/or frame and/or stack pointers.

    Bounds check instructions are used to check if an array reference is out of bounds.

    Digital Equipment Corporation’s “VAX Architecture Reference Manual” gives the following example of the CASE instruction using the VAX PASCAL compiler (quoted under the fair use doctrine):

    case i of
    32: x := sin(x);
    33: x := cos(x);
    34: x := exp(x);
    35: x := ln(x);
    36, 37: x := arctanh(x);
    otherwise x := reserved
    end

    casel i, #32, <#37-32>
    1$: .word sin - 1$ ; Selector is 32.
    .word cos - 1$ ; Selector is 33.
    .word exp - 1$ ; Selector is 34.
    .word ln - 1$ ; Selector is 35.
    .word arctanh - 1$ ; Selector is 36.
    .word arctanh - 1$ ; Selector is 37.
    otherwise:
    movl reserved, x ; Selector is less than.
    ; 32 or greater than 37

    Now building a [For those with high speed connections, the very large single file ](../../milo/milo.html>free emulator and assembly language proigramming lessons.

    free music player coding example

    Programming example: I am making heavily documented and explained open source PHP/MySQL code for a method to play music for free — almost any song, no subscription fees, no download costs, no advertisements, all completely legal. This is done by building a front-end to YouTube (which checks the copyright permissions for you).

    View music player in action: www.musicinpublic.com/.

    Create your own copy from the original source code/ (presented for learning programming). Includes how to run this from your own computer if you don’t have a web site.


    return to table of contents
    free downloadable college text book

    view text book

    HTML file

    Because I no longer have the computer and software to make PDFs, the book is available as an HTML file, which you can convert into a PDF.


    A web site on dozens of operating systems simply can’t be maintained by one person. This is a cooperative effort. If you spot an error in fact, grammar, syntax, or spelling, or a broken link, or have additional information, commentary, or constructive criticism, please e-mail Milo. If you have any extra copies of docs, manuals, or other materials that can assist in accuracy and completeness, please send them to Milo, PO Box 1361, Tustin, CA, USA, 92781.

    Click here for our privacy policy.


    home page

    two levels up

    special topics

    one level up

    peer level

    free computer programming text book project

    Building a free downloadable text book on computer programming for university, college, community college, and high school classes in computer programming.

    If you like the idea of this project,
    then please donate some money.

    send donations to:
    Milo
    PO Box 1361
    Tustin, California 92781

    Supporting the entire project:

    If you have a business or organization that can support the entire cost of this project, please contact Pr Ntr Kmt (my church)

    more information on donating

    Some or all of the material on this web page appears in the
    free downloadable college text book on computer programming.


    I do the news as an unpaid volunteer for KOCI 101.5 FM, Newport Beach/Costa Mesa (also available on the web)


    Made with Macintosh

    This web site handcrafted on Macintosh computers using Tom Bender’s Tex-Edit Plus and served using FreeBSD .

    Viewable With Any Browser


    Names and logos of various OSs are trademarks of their respective owners.

    Copyright © 2000, 2001, 2010 Milo

    Created: February 21, 2001 (from machcode.htm)

    Last Updated: December 1, 2010


    return to table of contents
    free downloadable college text book