comp.lang.ada
 help / color / mirror / Atom feed
From: NiGHTS <nights@unku.us>
Subject: Re: Using pointers with inline assembly in Ada
Date: Fri, 10 Jun 2022 05:23:52 -0700 (PDT)	[thread overview]
Message-ID: <1eb8caa1-60e0-4e30-bb7b-c06969129970n@googlegroups.com> (raw)
In-Reply-To: <nnd$727405a5$1c8a5b81@aedbf58048bf777d>

On Friday, June 10, 2022 at 3:15:38 AM UTC-4, ldries46 wrote:
> Op 10-6-2022 om 7:24 schreef Rod Kay:
> On 10/6/22 07:30, NiGHTS wrote: 
> declare 
>           type ff is array (0 .. 10) of Unsigned_32; 
>           pragma Pack(ff); 
>           Flags : aliased ff := (others => 0); 
>           Flag_Address : System.Address := Flags'Address; 
> begin 
>          Asm (   "movl %0, %%eax" & 
>                  "movl $1, (%%eax)" , 
>                  Inputs   => System.Address'Asm_Input ("g", Flag_Address), 
>                  Clobber  => "eax", 
>                  Volatile => true 
>          ); 
>          Put_Line ("Output:" & Flags(0)'Img); 
> end; 
> 
> 
>    If you are on a 64 bit machine, then I expect 'pragma Pack' might be the problem, as 2 consecutive array elements will fir into a single address. 
> 
> 
>    Also, possibly use ... 
> 
>    Flag_Address : System.Address := Flags (Flags'First)'Address; 
> 
> 
> Regards.
> There maybe a a way around this problem, if there is a compiler that can create assembly code. I have used that method in the past with Pascal programs where I wanted to avoid internal checks on errors that could not occur in that part of the program.
> 
> Warning: Programming the way you want to means that your program will mean that your program can become depending on the system you are working on. Meaning for instance not only recompiling when migrating from Windows to Linux but also reprogramming that part of your work

Ada does a good job generating efficient machine code, and there are lots of ways to get around compiler checks (unlike Pascal). In this situation I was trying to make use of a very specific set of uncommon CPU instructions but required passing an array to it that allows side-effects. I'm a bit peeved that there is so little in the way of documentation for the Asm command.

  parent reply	other threads:[~2022-06-10 12:23 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-06-09 21:30 Using pointers with inline assembly in Ada NiGHTS
2022-06-10  5:24 ` Rod Kay
2022-06-10 11:16   ` Luke A. Guest
2022-06-10 12:26     ` NiGHTS
2022-06-10 12:16   ` NiGHTS
2022-06-10 13:19     ` Jeffrey R.Carter
     [not found]   ` <nnd$727405a5$1c8a5b81@aedbf58048bf777d>
2022-06-10 12:23     ` NiGHTS [this message]
2022-06-11  1:43   ` Rod Kay
2022-06-10 13:39 ` Jeffrey R.Carter
2022-06-11  1:51   ` NiGHTS
2022-06-11 12:28 ` Simon Wright
2022-06-11 12:32   ` NiGHTS
2022-06-13 20:33 ` Gabriele Galeotti
replies disabled

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