Expand/Shrink

Machine Level Interface

We have grouped here a number of routines that you can use to access your machine at a low-level.
With this low-level machine interface you can read and write to memory.
You can also set up your own machine language routines and call them.

Some of the routines listed below are unsafe, in the sense that Phix cannot protect you if you use them incorrectly. You could crash your program or even your system.

Under Windows, the operating system will usually pop up a termination box giving a diagnostic message plus register information.
Under Linux you will typically get a segmentation violation.
Note there is no such thing as safe.e for Phix, that is Euphoria-only.

These machine-level-interface routines are important because they allow access to low-level features of the hardware and operating system.
For some applications this is essential.

Machine code routines can be written by hand, or taken from the disassembled output of a compiler for C or some other language.
There are many examples of inline assembly needed for the Phix runtime, perhaps the simplest of which is builtins\VM\pLen.e which implements the length() function (but only when the compiler does not inline it, as per the technicalia dropdown on that link).

Only int_to_bytes() and bytes_to_int() are supported by pwa/p2js.
 
peek - read one or more bytes from memory
poke - write one or more bytes to memory
mem_copy - copy a block of memory
mem_set - set a block of memory to a value
call - call a machine language routine
allocate - allocate a block of memory
free - deallocate a block of memory
allocate_string - allocate a string of characters with 0 terminator
int_to_bytes - convert an integer to a sequence of bytes
bytes_to_int - convert a sequence of bytes to an integer
int_to_bits - convert an integer to a sequence of bits
bits_to_int - convert a sequence of bits to an integer
atom_to_floatNN - convert an atom to a sequence of 4/8/10 bytes in IEEE 32/64/80-bit floating-point format
floatNN_to_atom - convert a sequence of 4/8/10 bytes in IEEE 32/64/80-bit floating-point format, to an atom