comp.lang.ada
 help / color / mirror / Atom feed
* Executing machine code?
@ 1999-05-27  0:00 Ikram
  1999-05-27  0:00 ` David Brown
  1999-05-27  0:00 ` Samuel Mize
  0 siblings, 2 replies; 4+ messages in thread
From: Ikram @ 1999-05-27  0:00 UTC (permalink / raw)


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.:

  char code[MAX]; /* storage area for function's code. */
  code[0] = 0x55; /* code making up the function's preamble. */
  code[1] = ...
  ...
  code[x] = ... /* code making up the function's body. */
  code[x+1] = ...
  ...
  code[MAX-1] = 0xC3; /* return instruction. */
  
  /* now cast array pointer into a function pointer.  assume this 
     function takes one int argument and returns an int result, 
     using C parameter passing conventions. */
  f = (int (*)(int))code; 
  result = f(4); /* call the function. */

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).  or perhaps someone would
like to suggest an alternative means of executing machine code
generated on-the-fly from within Ada programs?  suggestions or
pointers to information would be welcome.

thanks,
Ikram
-- 
I. M. Ikram   <URL:http://www.cs.und.ac.za/~ikram/>   ikram@cs.und.ac.za




^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~1999-05-28  0:00 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
1999-05-27  0:00 Executing machine code? Ikram
1999-05-27  0:00 ` David Brown
1999-05-27  0:00 ` Samuel Mize
1999-05-28  0:00   ` Robert Dewar

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox