From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on polar.synack.me X-Spam-Level: X-Spam-Status: No, score=-1.3 required=5.0 tests=BAYES_00,INVALID_MSGID autolearn=no autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,1140c4e8eb3fd28f X-Google-Attributes: gid103376,public From: Samuel Mize Subject: Re: Executing machine code? Date: 1999/05/27 Message-ID: <7ijqgs$26o@news2.newsguy.com>#1/1 X-Deja-AN: 482771884 References: <86u2sya7od.fsf@finch.cs.und.ac.za> Organization: ImagiNet Communications, Ltd. User-Agent: tin/pre-1.4-981002 ("Phobia") (UNIX) (AIX/3-2) Newsgroups: comp.lang.ada Date: 1999-05-27T00:00:00+00:00 List-Id: Ikram wrote: > I occasionally need to write programs that generate and execute > machine code (as in e.g. genetic programming systems). in C, the > method I've been using is to store the machine instructions in an > array of bytes, and then cast the array into a function, e.g.: My word. I doubt you'll find a large body of people with experience in this area. :-) > I'm trying to find out whether it is similarly possible to switch > between array and function representations in Ada (not necessarily in > a platform- or compiler-independent way). I think you can accomplish what you want, at least with some compilers. You'll need a compiler that supports the syntax for machine-language instructions. Write a routine that determines the address of the first byte in your array of bytes, and then does a machine-language subroutine jump to that address. I specify "first byte in the array" because some compilers, at least some older Ada 83 compilers, may return the address of a dope vector if you just use 'address. You may need to decide where to put the array in memory, and use a representation clause to put it there. Best of luck, and let us know how it works out! Sam Mize -- Samuel Mize -- smize@imagin.net (home email) -- Team Ada Fight Spam: see http://www.cauce.org/ \\\ Smert Spamonam