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.9 required=5.0 tests=BAYES_00 autolearn=ham autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,9f3d09bde7b33b5d X-Google-Attributes: gid103376,public X-Google-ArrivalTime: 2004-04-17 01:03:38 PST Path: archiver1.google.com!news1.google.com!news.glorb.com!newsrout1.ntli.net!news.ntli.net!kibo.news.demon.net!news.demon.co.uk!demon!not-for-mail From: Simon Wright Newsgroups: comp.lang.ada Subject: Re: Pass by reference Date: 17 Apr 2004 08:59:20 +0100 Organization: Pushface Sender: simon@smaug.pushface.org Message-ID: References: <19b0e504.0404080652.4eab9f80@posting.google.com> <5QAdc.7896$Jf6.4030@newssvr23.news.prodigy.com> <4hen70p62fq82m89cc52t6kutg44k757tf@jellix.jlfencey.com> <22js70he63r733ip61lqt4amgcp6c8btp1@jellix.jlfencey.com> NNTP-Posting-Host: pogner.demon.co.uk Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Trace: news.demon.co.uk 1082189017 8542 62.49.19.209 (17 Apr 2004 08:03:37 GMT) X-Complaints-To: abuse@demon.net NNTP-Posting-Date: Sat, 17 Apr 2004 08:03:37 +0000 (UTC) User-Agent: Gnus/5.09 (Gnus v5.9.0) Emacs/21.1 Xref: archiver1.google.com comp.lang.ada:7243 Date: 2004-04-17T08:59:20+01:00 List-Id: Vinzent 'Gadget' Hoefler writes: > Simon Wright wrote: > >I'm not 100% sure on this, but this code > > > > with Interfaces; > > with System.Machine_Code; > > with System.Storage_Elements; > > > > procedure Access_Memory_Mapped_Register is > [...] > > #APP > > movl #01000000, -65536 > > movl #00000000, -65536 > > #NO_APP > > (Despite the fact that this code is not valid, i386 can't load two > constants in one instruction, your intention is clear and would > work). Yes, more work needed (and next time, Simon, go the whole way and don't just stop with a -S compilation). I too will only use asm when it's _necessary_, so it's a new learning experience each time ... > That's why I declared the procedure to take an access parameter > instead of "in out" and now everything is working fine as > expected. It is just the fact that I now use access types in the > interface (IMO: unnecessarily from the point of logic) that bugs me > a little bit. Another possibility would be to pass System.Address. On the whole, access is a lot safer I would have thought -- especially if you can encapsulate this low-level stuff (including the calls to your wrapper procedure) to a restricted area of the code. > Eventually I should try to switch to use limited types instead to > circumvent this problem? I had a play with this, and for GNAT 3.15p (and 3.16a1, 5.02a) this package Wrapper is type Register is limited private; procedure Write (Value : Interfaces.Unsigned_16; To : in out Register); private type Actual_Register is mod 256; for Actual_Register'Size use 8; pragma Volatile (Actual_Register); type Register is limited record Actual : Actual_Register; end record; for Register'Size use 8; end Wrapper; used pass-by-reference. The asm for 5.02a (-gnatp -O2) is .type access_memory_mapped_register__wrapper__write.0,@function access_memory_mapped_register__wrapper__write.0: .LFB1: pushl %ebp .LCFI0: movl %esp, %ebp .LCFI1: subl $4, %esp .LCFI2: movzwl 8(%ebp), %eax movl 12(%ebp), %edx movb %al, (%edx) shrl $8, %eax movb %al, (%edx) movl %ebp, %esp popl %ebp ret which looks as though it at least stands a chance; I don't understand the 3.15p code, .type access_memory_mapped_register__wrapper__write.0,@function access_memory_mapped_register__wrapper__write.0: pushl %ebp movl %esp,%ebp subl $4,%esp movl %ecx,-4(%ebp) movl 12(%ebp),%edx movzbw 9(%ebp),%ax movb %al,(%edx) movl %ebp,%esp popl %ebp ret -- Simon Wright 100% Ada, no bugs.