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=-0.9 required=5.0 tests=BAYES_00,FORGED_GMAIL_RCVD, FREEMAIL_FROM,T_FILL_THIS_FORM_SHORT autolearn=no autolearn_force=no version=3.4.4 X-Google-Thread: 103376,c9d5fc258548b22a X-Google-NewGroupId: yes X-Google-Attributes: gida07f3367d7,domainid0,public,usenet X-Google-Language: ENGLISH,ASCII Path: g2news1.google.com!postnews.google.com!m27g2000prj.googlegroups.com!not-for-mail From: Edward Fish Newsgroups: comp.lang.ada Subject: Re: How do I write directly to a memory address? Date: Fri, 11 Feb 2011 20:47:35 -0800 (PST) Organization: http://groups.google.com Message-ID: <8e200ae9-51c7-4756-9d06-7b5dbc6eb85c@m27g2000prj.googlegroups.com> References: <67063a5b-f588-45ea-bf22-ca4ba0196ee6@l11g2000yqb.googlegroups.com> NNTP-Posting-Host: 174.28.151.164 Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable X-Trace: posting.google.com 1297486154 21686 127.0.0.1 (12 Feb 2011 04:49:14 GMT) X-Complaints-To: groups-abuse@google.com NNTP-Posting-Date: Sat, 12 Feb 2011 04:49:14 +0000 (UTC) Complaints-To: groups-abuse@google.com Injection-Info: m27g2000prj.googlegroups.com; posting-host=174.28.151.164; posting-account=IGEw6QoAAAChe8btAoGmJk0kqF3q3VLA User-Agent: G2/1.0 X-HTTP-UserAgent: Mozilla/5.0 (Windows; U; Windows NT 6.0; en-US; rv:1.9.2.13) Gecko/20101203 Firefox/3.6.13 ( .NET CLR 3.5.30729; .NET4.0E),gzip(gfe) Xref: g2news1.google.com comp.lang.ada:17256 Date: 2011-02-11T20:47:35-08:00 List-Id: On Feb 2, 10:52=A0pm, Syntax Issues wrote: > I am planning to start learning lower-level programming with ada, > however, I was unable to find a solid tutorial on writing directly to > a memory address or interfacing with assembly. Does anyone know where > I can find a reference to some tutorials/information? Below is an > example of code I would like to be able to implement. > As others have replied using the 'Address attribute on a constrained array of your video's cell-type {attribute-character pair}is the way to go. But if you're using GNAT you may have noticed that it doesn't allow a straight "For Data'Address Use 16#000B_8000#;" because GNAT uses a private type and not a derivative of Universal_Integer. They recommend an implementation-dependent "to_Address" function, but that would make things non-portable. After some thought and some fiddling here's a portable, insofar as I know, method to convert an integer literal or constant (or even variable) to an address containing that value. -- Address_Overlay.ads; Pragma pure may be added. With System; Package Address_Overlay is Type Address_Integer is Range 0..System.Memory_Size; Private End Address_Overlay; ----- Address_Overlay.This.ads; an instantiation of ----- this provides the proper overlay Generic Value : Address_Integer; Package Address_Overlay.This is Address : Constant System.Address; -- Overlay Address with Value. Private Pragma Warnings (Off, "*overlay*"); -- Here we turn off the warning For Address'Address Use Value'Address; -- about a constant overlaying Pragma Import( Ada, Address ); -- a variable; as that is our Pragma Warnings (On, "*overlay*"); -- intention. End Address_Overlay.This; ----------- -- USAGE -- ----------- Declare Package An_Address( 16#000C_8000# ); Data : Integer; For Data'Address Use An_Address.Address; Begin Data:=3D 4; End;