Rocksolid Light

Welcome to novaBBS (click a section below)

mail  files  register  newsreader  groups  login

Message-ID:  

Klingon phaser attack from front!!!!! 100% Damage to life support!!!!


devel / comp.lang.ada / Using pointers with inline assembly in Ada

SubjectAuthor
* Using pointers with inline assembly in AdaNiGHTS
+* Re: Using pointers with inline assembly in AdaRod Kay
|+* Re: Using pointers with inline assembly in AdaLuke A. Guest
||`- Re: Using pointers with inline assembly in AdaNiGHTS
|+* Re: Using pointers with inline assembly in AdaNiGHTS
||`- Re: Using pointers with inline assembly in AdaJeffrey R.Carter
|+- Re: Using pointers with inline assembly in AdaNiGHTS
|`- Re: Using pointers with inline assembly in AdaRod Kay
+* Re: Using pointers with inline assembly in AdaJeffrey R.Carter
|`- Re: Using pointers with inline assembly in AdaNiGHTS
+* Re: Using pointers with inline assembly in AdaSimon Wright
|`- Re: Using pointers with inline assembly in AdaNiGHTS
`- Re: Using pointers with inline assembly in AdaGabriele Galeotti

1
Using pointers with inline assembly in Ada

<db04b8e7-ba96-4f4a-afb1-575e446ace64n@googlegroups.com>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=7026&group=comp.lang.ada#7026

  copy link   Newsgroups: comp.lang.ada
X-Received: by 2002:a37:a9c4:0:b0:6a6:8992:e400 with SMTP id s187-20020a37a9c4000000b006a68992e400mr25947181qke.494.1654810220248;
Thu, 09 Jun 2022 14:30:20 -0700 (PDT)
X-Received: by 2002:a0d:ee47:0:b0:2ff:85e6:9e03 with SMTP id
x68-20020a0dee47000000b002ff85e69e03mr45281706ywe.172.1654810220048; Thu, 09
Jun 2022 14:30:20 -0700 (PDT)
Path: i2pn2.org!i2pn.org!usenet.blueworldhosting.com!feed1.usenet.blueworldhosting.com!peer01.iad!feed-me.highwinds-media.com!news.highwinds-media.com!news-out.google.com!nntp.google.com!postnews.google.com!google-groups.googlegroups.com!not-for-mail
Newsgroups: comp.lang.ada
Date: Thu, 9 Jun 2022 14:30:18 -0700 (PDT)
Injection-Info: google-groups.googlegroups.com; posting-host=98.211.187.237; posting-account=Ru7E4QoAAAC_HiQ2D8LjZ7rh1mbTNcVn
NNTP-Posting-Host: 98.211.187.237
User-Agent: G2/1.0
MIME-Version: 1.0
Message-ID: <db04b8e7-ba96-4f4a-afb1-575e446ace64n@googlegroups.com>
Subject: Using pointers with inline assembly in Ada
From: nig...@unku.us (NiGHTS)
Injection-Date: Thu, 09 Jun 2022 21:30:20 +0000
Content-Type: text/plain; charset="UTF-8"
X-Received-Bytes: 1909
 by: NiGHTS - Thu, 9 Jun 2022 21:30 UTC

I would like to write an inline assembly code in Ada that simply writes a constant to a specific element of an array of unsigned values.

I'm shooting in the dark here because there are absolutely no references on this subject, to my surprise.

This was my first experiment which produces a memory access error. In this early version I'm just trying to write to the first element.

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;

Any help would be greatly appreciated!

Re: Using pointers with inline assembly in Ada

<t7ukpe$759$1@dont-email.me>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=7028&group=comp.lang.ada#7028

  copy link   Newsgroups: comp.lang.ada
Path: i2pn2.org!i2pn.org!eternal-september.org!reader02.eternal-september.org!.POSTED!not-for-mail
From: rodak...@gmail.com (Rod Kay)
Newsgroups: comp.lang.ada
Subject: Re: Using pointers with inline assembly in Ada
Date: Fri, 10 Jun 2022 15:24:35 +1000
Organization: A noiseless patient Spider
Lines: 27
Message-ID: <t7ukpe$759$1@dont-email.me>
References: <db04b8e7-ba96-4f4a-afb1-575e446ace64n@googlegroups.com>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Date: Fri, 10 Jun 2022 05:28:14 -0000 (UTC)
Injection-Info: reader02.eternal-september.org; posting-host="eeb844e01c63fc18280f71d34dd7074e";
logging-data="7337"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/MSgvRIgi30U96ozOa4cm/3LSPDcFjPXE="
User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:91.0) Gecko/20100101
Thunderbird/91.9.1
Cancel-Lock: sha1:zLW0oyU1DCOk4qT/ZGgiFaMJflM=
In-Reply-To: <db04b8e7-ba96-4f4a-afb1-575e446ace64n@googlegroups.com>
Content-Language: en-US
 by: Rod Kay - Fri, 10 Jun 2022 05:24 UTC

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.

Re: Using pointers with inline assembly in Ada

<t7v995$4lk$1@gioia.aioe.org>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=7029&group=comp.lang.ada#7029

  copy link   Newsgroups: comp.lang.ada
Path: i2pn2.org!i2pn.org!aioe.org!Lx7EM+81f32E0bqku+QpCA.user.46.165.242.75.POSTED!not-for-mail
From: lagu...@archeia.com (Luke A. Guest)
Newsgroups: comp.lang.ada
Subject: Re: Using pointers with inline assembly in Ada
Date: Fri, 10 Jun 2022 12:16:27 +0100
Organization: Aioe.org NNTP Server
Message-ID: <t7v995$4lk$1@gioia.aioe.org>
References: <db04b8e7-ba96-4f4a-afb1-575e446ace64n@googlegroups.com>
<t7ukpe$759$1@dont-email.me>
Mime-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 8bit
Injection-Info: gioia.aioe.org; logging-data="4788"; posting-host="Lx7EM+81f32E0bqku+QpCA.user.gioia.aioe.org"; mail-complaints-to="abuse@aioe.org";
User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:91.0) Gecko/20100101
Thunderbird/91.9.1
Content-Language: en-GB
X-Notice: Filtered by postfilter v. 0.9.2
 by: Luke A. Guest - Fri, 10 Jun 2022 11:16 UTC

On 10/06/2022 06:24, Rod Kay wrote:
> 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.

Dump the xpanded (generated code) and the assembly from gnat.

Re: Using pointers with inline assembly in Ada

<cb332860-e55d-48a7-81b2-1ed1edf45dcan@googlegroups.com>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=7030&group=comp.lang.ada#7030

  copy link   Newsgroups: comp.lang.ada
X-Received: by 2002:a05:620a:258e:b0:680:f33c:dbcd with SMTP id x14-20020a05620a258e00b00680f33cdbcdmr31079667qko.542.1654863401367;
Fri, 10 Jun 2022 05:16:41 -0700 (PDT)
X-Received: by 2002:a0d:eacc:0:b0:30c:30cc:e161 with SMTP id
t195-20020a0deacc000000b0030c30cce161mr47364215ywe.375.1654863401122; Fri, 10
Jun 2022 05:16:41 -0700 (PDT)
Path: i2pn2.org!i2pn.org!usenet.blueworldhosting.com!feed1.usenet.blueworldhosting.com!peer03.iad!feed-me.highwinds-media.com!news.highwinds-media.com!news-out.google.com!nntp.google.com!postnews.google.com!google-groups.googlegroups.com!not-for-mail
Newsgroups: comp.lang.ada
Date: Fri, 10 Jun 2022 05:16:40 -0700 (PDT)
In-Reply-To: <t7ukpe$759$1@dont-email.me>
Injection-Info: google-groups.googlegroups.com; posting-host=73.205.150.94; posting-account=Ru7E4QoAAAC_HiQ2D8LjZ7rh1mbTNcVn
NNTP-Posting-Host: 73.205.150.94
References: <db04b8e7-ba96-4f4a-afb1-575e446ace64n@googlegroups.com> <t7ukpe$759$1@dont-email.me>
User-Agent: G2/1.0
MIME-Version: 1.0
Message-ID: <cb332860-e55d-48a7-81b2-1ed1edf45dcan@googlegroups.com>
Subject: Re: Using pointers with inline assembly in Ada
From: nig...@unku.us (NiGHTS)
Injection-Date: Fri, 10 Jun 2022 12:16:41 +0000
Content-Type: text/plain; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable
X-Received-Bytes: 2438
 by: NiGHTS - Fri, 10 Jun 2022 12:16 UTC

On Friday, June 10, 2022 at 1:28:17 AM UTC-4, roda...@gmail.com wrote:
> 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.

Thank you for your response. Unfortunately this didn't seem to work. I agree that the pragma was misused, though that shouldn't have caused the error accessing the first element. I also am not entirely sure why there would be a difference between the address of the first element versus the address of the array itself (maybe that's just my C instincts kicking in).

Re: Using pointers with inline assembly in Ada

<1eb8caa1-60e0-4e30-bb7b-c06969129970n@googlegroups.com>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=7031&group=comp.lang.ada#7031

  copy link   Newsgroups: comp.lang.ada
X-Received: by 2002:a05:6214:21e5:b0:46d:82b5:b1a2 with SMTP id p5-20020a05621421e500b0046d82b5b1a2mr7590816qvj.116.1654863832993;
Fri, 10 Jun 2022 05:23:52 -0700 (PDT)
X-Received: by 2002:a25:4142:0:b0:664:6927:7b87 with SMTP id
o63-20020a254142000000b0066469277b87mr2023728yba.100.1654863832777; Fri, 10
Jun 2022 05:23:52 -0700 (PDT)
Path: i2pn2.org!rocksolid2!i2pn.org!paganini.bofh.team!pasdenom.info!nntpfeed.proxad.net!proxad.net!feeder1-2.proxad.net!209.85.160.216.MISMATCH!news-out.google.com!nntp.google.com!postnews.google.com!google-groups.googlegroups.com!not-for-mail
Newsgroups: comp.lang.ada
Date: Fri, 10 Jun 2022 05:23:52 -0700 (PDT)
In-Reply-To: <nnd$727405a5$1c8a5b81@aedbf58048bf777d>
Injection-Info: google-groups.googlegroups.com; posting-host=73.205.150.94; posting-account=Ru7E4QoAAAC_HiQ2D8LjZ7rh1mbTNcVn
NNTP-Posting-Host: 73.205.150.94
References: <db04b8e7-ba96-4f4a-afb1-575e446ace64n@googlegroups.com>
<t7ukpe$759$1@dont-email.me> <nnd$727405a5$1c8a5b81@aedbf58048bf777d>
User-Agent: G2/1.0
MIME-Version: 1.0
Message-ID: <1eb8caa1-60e0-4e30-bb7b-c06969129970n@googlegroups.com>
Subject: Re: Using pointers with inline assembly in Ada
From: nig...@unku.us (NiGHTS)
Injection-Date: Fri, 10 Jun 2022 12:23:52 +0000
Content-Type: text/plain; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable
 by: NiGHTS - Fri, 10 Jun 2022 12:23 UTC

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.

Re: Using pointers with inline assembly in Ada

<b9e88f0b-5af7-4939-aef1-e054fd158fc9n@googlegroups.com>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=7032&group=comp.lang.ada#7032

  copy link   Newsgroups: comp.lang.ada
X-Received: by 2002:a05:622a:1787:b0:304:e74c:ae47 with SMTP id s7-20020a05622a178700b00304e74cae47mr25479573qtk.285.1654864016948;
Fri, 10 Jun 2022 05:26:56 -0700 (PDT)
X-Received: by 2002:a25:8610:0:b0:664:5ccf:94af with SMTP id
y16-20020a258610000000b006645ccf94afmr4021301ybk.379.1654864016775; Fri, 10
Jun 2022 05:26:56 -0700 (PDT)
Path: i2pn2.org!rocksolid2!i2pn.org!usenet.blueworldhosting.com!feed1.usenet.blueworldhosting.com!peer03.iad!feed-me.highwinds-media.com!news.highwinds-media.com!news-out.google.com!nntp.google.com!postnews.google.com!google-groups.googlegroups.com!not-for-mail
Newsgroups: comp.lang.ada
Date: Fri, 10 Jun 2022 05:26:56 -0700 (PDT)
In-Reply-To: <t7v995$4lk$1@gioia.aioe.org>
Injection-Info: google-groups.googlegroups.com; posting-host=73.205.150.94; posting-account=Ru7E4QoAAAC_HiQ2D8LjZ7rh1mbTNcVn
NNTP-Posting-Host: 73.205.150.94
References: <db04b8e7-ba96-4f4a-afb1-575e446ace64n@googlegroups.com>
<t7ukpe$759$1@dont-email.me> <t7v995$4lk$1@gioia.aioe.org>
User-Agent: G2/1.0
MIME-Version: 1.0
Message-ID: <b9e88f0b-5af7-4939-aef1-e054fd158fc9n@googlegroups.com>
Subject: Re: Using pointers with inline assembly in Ada
From: nig...@unku.us (NiGHTS)
Injection-Date: Fri, 10 Jun 2022 12:26:56 +0000
Content-Type: text/plain; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable
X-Received-Bytes: 2871
 by: NiGHTS - Fri, 10 Jun 2022 12:26 UTC

On Friday, June 10, 2022 at 7:18:03 AM UTC-4, Luke A. Guest wrote:
> On 10/06/2022 06:24, Rod Kay wrote:
> > 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.
> Dump the xpanded (generated code) and the assembly from gnat.

Though that wouldn't be a bad idea, I've decided to do this another way. I have a limited time to work on this project and I'm just not feeling it. Too risky to work on something this important with so little documentation. I figured I'd give the problem the due-diligence of posting the question on here but I've made up my mind that at least with the project I am working on that I write the code in C/Asm instead. Thank you for your help though.

Re: Using pointers with inline assembly in Ada

<t7vgd2$7v6$1@dont-email.me>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=7033&group=comp.lang.ada#7033

  copy link   Newsgroups: comp.lang.ada
Path: i2pn2.org!i2pn.org!eternal-september.org!reader02.eternal-september.org!.POSTED!not-for-mail
From: spam.jrc...@spam.acm.org.not (Jeffrey R.Carter)
Newsgroups: comp.lang.ada
Subject: Re: Using pointers with inline assembly in Ada
Date: Fri, 10 Jun 2022 15:19:30 +0200
Organization: A noiseless patient Spider
Lines: 18
Message-ID: <t7vgd2$7v6$1@dont-email.me>
References: <db04b8e7-ba96-4f4a-afb1-575e446ace64n@googlegroups.com>
<t7ukpe$759$1@dont-email.me>
<cb332860-e55d-48a7-81b2-1ed1edf45dcan@googlegroups.com>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Date: Fri, 10 Jun 2022 13:19:30 -0000 (UTC)
Injection-Info: reader02.eternal-september.org; posting-host="57e2f04b319b314c1505a3472859f8ad";
logging-data="8166"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/2mWlEEmN92jAQ20OYqH7oLETjjRHzXA4="
User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:91.0) Gecko/20100101
Thunderbird/91.9.1
Cancel-Lock: sha1:YY0RwKSDkhptF0YYcKCIuvkHZlM=
In-Reply-To: <cb332860-e55d-48a7-81b2-1ed1edf45dcan@googlegroups.com>
Content-Language: en-US
 by: Jeffrey R.Carter - Fri, 10 Jun 2022 13:19 UTC

On 2022-06-10 14:16, NiGHTS wrote:
>
> I also am not entirely sure why there would be a difference between the address of the first element versus the address of the array itself (maybe that's just my C instincts kicking in).

Unlike C, an Ada array has associated bounds information. Sometimes that bounds
information is physically stored with the array data, usually before them. There
is implementation advice that A'Address and A (A'First)'Address should give the
same address, but some compilers return the address of the bounds information.

In your particular case, the bounds are static, so the compiler probably doesn't
store them, and GNAT follows the implementation advice, so there is no
difference in the two forms in any case.

--
Jeff Carter
"I'm a lumberjack and I'm OK."
Monty Python's Flying Circus
54

Re: Using pointers with inline assembly in Ada

<t7vhit$ar$1@dont-email.me>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=7034&group=comp.lang.ada#7034

  copy link   Newsgroups: comp.lang.ada
Path: i2pn2.org!i2pn.org!eternal-september.org!reader02.eternal-september.org!.POSTED!not-for-mail
From: spam.jrc...@spam.acm.org.not (Jeffrey R.Carter)
Newsgroups: comp.lang.ada
Subject: Re: Using pointers with inline assembly in Ada
Date: Fri, 10 Jun 2022 15:39:41 +0200
Organization: A noiseless patient Spider
Lines: 39
Message-ID: <t7vhit$ar$1@dont-email.me>
References: <db04b8e7-ba96-4f4a-afb1-575e446ace64n@googlegroups.com>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Date: Fri, 10 Jun 2022 13:39:41 -0000 (UTC)
Injection-Info: reader02.eternal-september.org; posting-host="57e2f04b319b314c1505a3472859f8ad";
logging-data="347"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX18VrtursUDLPobWQizBRm123Q/F+/Ja98Y="
User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:91.0) Gecko/20100101
Thunderbird/91.9.1
Cancel-Lock: sha1:PhTwNbmh76ASok1uqOIAl2vhlcY=
In-Reply-To: <db04b8e7-ba96-4f4a-afb1-575e446ace64n@googlegroups.com>
Content-Language: en-US
 by: Jeffrey R.Carter - Fri, 10 Jun 2022 13:39 UTC

On 2022-06-09 23: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;

Have you looked at the GNAT User's Guide section on this
(https://docs.adacore.com/live/wave/gnat_ugn/html/gnat_ugn/gnat_ugn/inline_assembler.html)?
I have never used this, but the first thing I notice is that the examples in the
User's Guide put an LF-HT pair between statements:

Asm ("pushfl" & LF & HT & -- push flags on stack
"popl %%eax" & LF & HT & -- load eax with flags
"movl %%eax, %0", -- store flags in variable
Outputs => Unsigned_32'Asm_Output ("=g", Flags));

It is also legal to separate the statements with spaces, but what you have would
seem to be

movl %0, %%eaxmovl $1, (%%eax)

which may be a problem.

--
Jeff Carter
"I'm a lumberjack and I'm OK."
Monty Python's Flying Circus
54

Re: Using pointers with inline assembly in Ada

<t80s7o$dus$1@dont-email.me>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=7036&group=comp.lang.ada#7036

  copy link   Newsgroups: comp.lang.ada
Path: i2pn2.org!i2pn.org!eternal-september.org!reader02.eternal-september.org!.POSTED!not-for-mail
From: rodak...@gmail.com (Rod Kay)
Newsgroups: comp.lang.ada
Subject: Re: Using pointers with inline assembly in Ada
Date: Sat, 11 Jun 2022 11:43:59 +1000
Organization: A noiseless patient Spider
Lines: 13
Message-ID: <t80s7o$dus$1@dont-email.me>
References: <db04b8e7-ba96-4f4a-afb1-575e446ace64n@googlegroups.com>
<t7ukpe$759$1@dont-email.me>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 8bit
Injection-Date: Sat, 11 Jun 2022 01:47:36 -0000 (UTC)
Injection-Info: reader02.eternal-september.org; posting-host="32d0b6f8a05d4a88c3ff66659c6190e5";
logging-data="14300"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/1GL/eguJoAmd7U9dgLjJeqBuuJoWUzeM="
User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:91.0) Gecko/20100101
Thunderbird/91.9.1
Cancel-Lock: sha1:ltJAj64RV+CrO4fvaIS7JSFyplg=
In-Reply-To: <t7ukpe$759$1@dont-email.me>
Content-Language: en-US
 by: Rod Kay - Sat, 11 Jun 2022 01:43 UTC

On 10/6/22 15:24, Rod Kay wrote:
> On 10/6/22 07:30, NiGHTS wrote:
>
>    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.
>

Well, this is clearly nonsense. I don't know what I was thinking. I
suppose I was simply *not* thinking.

*Embarrassed*

Re: Using pointers with inline assembly in Ada

<c1f740b6-4dfe-4904-a73d-1957d6fb98c5n@googlegroups.com>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=7037&group=comp.lang.ada#7037

  copy link   Newsgroups: comp.lang.ada
X-Received: by 2002:a05:622a:1011:b0:304:fdc6:411b with SMTP id d17-20020a05622a101100b00304fdc6411bmr17101380qte.307.1654912263275;
Fri, 10 Jun 2022 18:51:03 -0700 (PDT)
X-Received: by 2002:a25:6744:0:b0:65d:46d6:d9a0 with SMTP id
b65-20020a256744000000b0065d46d6d9a0mr47724451ybc.467.1654912263095; Fri, 10
Jun 2022 18:51:03 -0700 (PDT)
Path: i2pn2.org!i2pn.org!usenet.blueworldhosting.com!feed1.usenet.blueworldhosting.com!peer02.iad!feed-me.highwinds-media.com!news.highwinds-media.com!news-out.google.com!nntp.google.com!postnews.google.com!google-groups.googlegroups.com!not-for-mail
Newsgroups: comp.lang.ada
Date: Fri, 10 Jun 2022 18:51:02 -0700 (PDT)
In-Reply-To: <t7vhit$ar$1@dont-email.me>
Injection-Info: google-groups.googlegroups.com; posting-host=73.205.150.94; posting-account=Ru7E4QoAAAC_HiQ2D8LjZ7rh1mbTNcVn
NNTP-Posting-Host: 73.205.150.94
References: <db04b8e7-ba96-4f4a-afb1-575e446ace64n@googlegroups.com> <t7vhit$ar$1@dont-email.me>
User-Agent: G2/1.0
MIME-Version: 1.0
Message-ID: <c1f740b6-4dfe-4904-a73d-1957d6fb98c5n@googlegroups.com>
Subject: Re: Using pointers with inline assembly in Ada
From: nig...@unku.us (NiGHTS)
Injection-Date: Sat, 11 Jun 2022 01:51:03 +0000
Content-Type: text/plain; charset="UTF-8"
X-Received-Bytes: 2635
 by: NiGHTS - Sat, 11 Jun 2022 01:51 UTC

On Friday, June 10, 2022 at 9:39:44 AM UTC-4, Jeffrey R.Carter wrote:
> On 2022-06-09 23: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;
> Have you looked at the GNAT User's Guide section on this
> (https://docs.adacore.com/live/wave/gnat_ugn/html/gnat_ugn/gnat_ugn/inline_assembler.html)?
> I have never used this, but the first thing I notice is that the examples in the
> User's Guide put an LF-HT pair between statements:
>
> Asm ("pushfl" & LF & HT & -- push flags on stack
> "popl %%eax" & LF & HT & -- load eax with flags
> "movl %%eax, %0", -- store flags in variable
> Outputs => Unsigned_32'Asm_Output ("=g", Flags));
>
> It is also legal to separate the statements with spaces, but what you have would
> seem to be
>
> movl %0, %%eaxmovl $1, (%%eax)
>
> which may be a problem.
> --
> Jeff Carter
> "I'm a lumberjack and I'm OK."
> Monty Python's Flying Circus
> 54
On my side I had the LF HT characters. I copied the code badly to this posting. So though you are right, my post lied a little bit by accident. This didn't end up being the main problem.

Re: Using pointers with inline assembly in Ada

<lyv8t7z8nr.fsf@pushface.org>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=7040&group=comp.lang.ada#7040

  copy link   Newsgroups: comp.lang.ada
Path: i2pn2.org!rocksolid2!i2pn.org!aioe.org!Nk+3gcWp7UG8G05s3m3vmg.user.46.165.242.75.POSTED!not-for-mail
From: sim...@pushface.org (Simon Wright)
Newsgroups: comp.lang.ada
Subject: Re: Using pointers with inline assembly in Ada
Date: Sat, 11 Jun 2022 13:28:24 +0100
Organization: Aioe.org NNTP Server
Message-ID: <lyv8t7z8nr.fsf@pushface.org>
References: <db04b8e7-ba96-4f4a-afb1-575e446ace64n@googlegroups.com>
Mime-Version: 1.0
Content-Type: text/plain
Injection-Info: gioia.aioe.org; logging-data="46761"; posting-host="Nk+3gcWp7UG8G05s3m3vmg.user.gioia.aioe.org"; mail-complaints-to="abuse@aioe.org";
User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/28.1 (darwin)
X-Notice: Filtered by postfilter v. 0.9.2
Cancel-Lock: sha1:BfUgrSy+l0z3+siSkPdrm8EWmQw=
 by: Simon Wright - Sat, 11 Jun 2022 12:28 UTC

NiGHTS <nights@unku.us> writes:

> This was my first experiment which produces a memory access error. In
> this early version I'm just trying to write to the first element.
>
> 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;

I got an access error as well (macOS, GCC 12.1.0, 64 bits).

Eventually, it turned out that the problem was that eax is a 32-bit
register. (the compiler used rdx, and the assembler told me that
movl %rdx, %eax wasn't allowed).

This is my working code; Flags is volatile, because otherwise the
compiler doesn't realise (at -O2) that Flags (0) has been touched.

ALso, note the Inputs line!

====
with System.Machine_Code; use System.Machine_Code;
with Interfaces; use Interfaces;
with Ada.Text_IO; use Ada.Text_IO;
procedure Nights is
type Ff is array (0 .. 10) of Unsigned_32;
Flags : aliased Ff := (others => 0) with Volatile;
begin
Asm (
"movq %0, %%rax" & ASCII.LF & ASCII.HT
& "movl $1, (%%rax)",
Inputs => System.Address'Asm_Input ("g", Flags (Flags'First)'Address),
Clobber => "rax",
Volatile => True
);
Put_Line ("Output:" & Flags(0)'Img);
end Nights;

Re: Using pointers with inline assembly in Ada

<7e9b7ba2-2304-4ffa-9bd3-d69a712cd022n@googlegroups.com>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=7041&group=comp.lang.ada#7041

  copy link   Newsgroups: comp.lang.ada
X-Received: by 2002:a05:622a:394:b0:304:eacb:2c69 with SMTP id j20-20020a05622a039400b00304eacb2c69mr26587932qtx.439.1654950754313;
Sat, 11 Jun 2022 05:32:34 -0700 (PDT)
X-Received: by 2002:a81:1d43:0:b0:313:a537:50ed with SMTP id
d64-20020a811d43000000b00313a53750edmr13121180ywd.335.1654950754068; Sat, 11
Jun 2022 05:32:34 -0700 (PDT)
Path: i2pn2.org!i2pn.org!usenet.blueworldhosting.com!feed1.usenet.blueworldhosting.com!peer03.iad!feed-me.highwinds-media.com!news.highwinds-media.com!news-out.google.com!nntp.google.com!postnews.google.com!google-groups.googlegroups.com!not-for-mail
Newsgroups: comp.lang.ada
Date: Sat, 11 Jun 2022 05:32:33 -0700 (PDT)
In-Reply-To: <lyv8t7z8nr.fsf@pushface.org>
Injection-Info: google-groups.googlegroups.com; posting-host=73.205.150.94; posting-account=Ru7E4QoAAAC_HiQ2D8LjZ7rh1mbTNcVn
NNTP-Posting-Host: 73.205.150.94
References: <db04b8e7-ba96-4f4a-afb1-575e446ace64n@googlegroups.com> <lyv8t7z8nr.fsf@pushface.org>
User-Agent: G2/1.0
MIME-Version: 1.0
Message-ID: <7e9b7ba2-2304-4ffa-9bd3-d69a712cd022n@googlegroups.com>
Subject: Re: Using pointers with inline assembly in Ada
From: nig...@unku.us (NiGHTS)
Injection-Date: Sat, 11 Jun 2022 12:32:34 +0000
Content-Type: text/plain; charset="UTF-8"
X-Received-Bytes: 2870
 by: NiGHTS - Sat, 11 Jun 2022 12:32 UTC

On Saturday, June 11, 2022 at 8:28:28 AM UTC-4, Simon Wright wrote:
> NiGHTS <nig...@unku.us> writes:
>
> > This was my first experiment which produces a memory access error. In
> > this early version I'm just trying to write to the first element.
> >
> > 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;
> I got an access error as well (macOS, GCC 12.1.0, 64 bits).
>
> Eventually, it turned out that the problem was that eax is a 32-bit
> register. (the compiler used rdx, and the assembler told me that
> movl %rdx, %eax wasn't allowed).
>
> This is my working code; Flags is volatile, because otherwise the
> compiler doesn't realise (at -O2) that Flags (0) has been touched.
>
> ALso, note the Inputs line!
>
> ====
> with System.Machine_Code; use System.Machine_Code;
> with Interfaces; use Interfaces;
> with Ada.Text_IO; use Ada.Text_IO;
> procedure Nights is
> type Ff is array (0 .. 10) of Unsigned_32;
> Flags : aliased Ff := (others => 0) with Volatile;
> begin
> Asm (
> "movq %0, %%rax" & ASCII.LF & ASCII.HT
> & "movl $1, (%%rax)",
> Inputs => System.Address'Asm_Input ("g", Flags (Flags'First)'Address),
> Clobber => "rax",
> Volatile => True
> );
> Put_Line ("Output:" & Flags(0)'Img);
> end Nights;
I haven't tested this yet but the solution makes sense to me. Thank you for your help!

Re: Using pointers with inline assembly in Ada

<01af1f18-5dd7-46d9-b082-36ae5b3c5811n@googlegroups.com>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=7052&group=comp.lang.ada#7052

  copy link   Newsgroups: comp.lang.ada
X-Received: by 2002:ae9:e8c4:0:b0:6a6:ab86:47ac with SMTP id a187-20020ae9e8c4000000b006a6ab8647acmr1592338qkg.48.1655152395129;
Mon, 13 Jun 2022 13:33:15 -0700 (PDT)
X-Received: by 2002:a0d:eacc:0:b0:30c:30cc:e161 with SMTP id
t195-20020a0deacc000000b0030c30cce161mr1646413ywe.375.1655152394825; Mon, 13
Jun 2022 13:33:14 -0700 (PDT)
Path: i2pn2.org!i2pn.org!weretis.net!feeder8.news.weretis.net!proxad.net!feeder1-2.proxad.net!209.85.160.216.MISMATCH!news-out.google.com!nntp.google.com!postnews.google.com!google-groups.googlegroups.com!not-for-mail
Newsgroups: comp.lang.ada
Date: Mon, 13 Jun 2022 13:33:14 -0700 (PDT)
In-Reply-To: <db04b8e7-ba96-4f4a-afb1-575e446ace64n@googlegroups.com>
Injection-Info: google-groups.googlegroups.com; posting-host=82.57.69.237; posting-account=JRF_-woAAABYlsAtkCl_CUxBuQy2SsaQ
NNTP-Posting-Host: 82.57.69.237
References: <db04b8e7-ba96-4f4a-afb1-575e446ace64n@googlegroups.com>
User-Agent: G2/1.0
MIME-Version: 1.0
Message-ID: <01af1f18-5dd7-46d9-b082-36ae5b3c5811n@googlegroups.com>
Subject: Re: Using pointers with inline assembly in Ada
From: gabriele...@gmail.com (Gabriele Galeotti)
Injection-Date: Mon, 13 Jun 2022 20:33:15 +0000
Content-Type: text/plain; charset="UTF-8"
 by: Gabriele Galeotti - Mon, 13 Jun 2022 20:33 UTC

On Thursday, June 9, 2022 at 11:30:21 PM UTC+2, NiGHTS wrote:
> I would like to write an inline assembly code in Ada that simply writes a constant to a specific element of an array of unsigned values.
>
> I'm shooting in the dark here because there are absolutely no references on this subject, to my surprise.
>
> This was my first experiment which produces a memory access error. In this early version I'm just trying to write to the first element.
>
> 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;
>
> Any help would be greatly appreciated!

Your code has no huge problems, apart generating a lot of warnings and being not decorated well.

Just make the array Volatile.

Otherwise the compiler is not able to understand that you're modifying the array,
takes that as an invariant, and prints a "0" instead of "1", optimizing everything
out away:

type ff is array (0 .. 10) of Unsigned_32; with
Pack => True,
Volatile => True;

There should be no problems for 64-bit machines because the components are anyway accessed on 32-bit boundaries,
but you have to adjust register sizes, EAX cannot contain an address in x86 64-bit mode (probably you have to use RAX).

G

1
server_pubkey.txt

rocksolid light 0.9.8
clearnet tor