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,ca0d61d183eeb881 X-Google-Attributes: gid103376,public From: jerry@jvdsys.stuyts.nl (Jerry van Dijk) Subject: Re: Direct memory access Date: 1999/03/25 Message-ID: #1/1 X-Deja-AN: 458922933 References: Organization: * JerryWare *, Leiden, Holland Newsgroups: comp.lang.ada Date: 1999-03-25T00:00:00+00:00 List-Id: Gordy (gbissell@coventry.ac.uk) wrote: : I'm trying to write some code to allow direct access to memory (for : testing memory on an embedded system). I simply want something like 'C' : pointers, so I can write/read values to a given memory address. : I've had a look at the Machine_Code package (to write my own functions) : but there must be a better way (i.e is there a function in the System : package which will allow writes to memory given a value and a : System.Address)? Yes, although you must have permission from the OS to access the memory. Simple example: ----------------------------------------------------------------------- with Ada.Text_IO; with System.Address_To_Access_Conversions; procedure Example is -------------------------- -- Create some memory -- -------------------------- type Byte is mod 2 ** 8; for Byte'Size use 8; Memory : array (0 .. 2048) of Byte := (others => 0); --------------------------------------- -- Create package to access memory -- --------------------------------------- package Byte_Conversions is new System.Address_To_Access_Conversions (Byte); ----------------- -- Variables -- ----------------- Byte_Ptr : Byte_Conversions.Object_Pointer; -- can hold an access value to a byte begin -- Write 10 values to memory for I in 512 .. 521 loop Byte_Ptr := Byte_Conversions.To_Pointer (Memory(I)'Address); Byte_Ptr.all := Byte (I - 512); end loop; -- Display 10 bytes from memory for I in 512 .. 521 loop Byte_Ptr := Byte_Conversions.To_Pointer (Memory(I)'Address); Ada.Text_IO.Put_Line (Byte'Image (Byte_Ptr.all)); end loop; end Example; ----------------------------------------------------------------------- -- -- Jerry van Dijk | Leiden, Holland -- Team Ada | jdijk@acm.org -- see http://stad.dsl.nl/~jvandyk