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,FREEMAIL_FROM autolearn=ham autolearn_force=no version=3.4.4 X-Google-Thread: a07f3367d7,87b54dbabc658fa2 X-Google-Attributes: gida07f3367d7,public,usenet X-Google-NewGroupId: yes X-Google-Language: ENGLISH,ASCII-7-bit X-Received: by 10.224.215.194 with SMTP id hf2mr42975162qab.0.1367290845460; Mon, 29 Apr 2013 20:00:45 -0700 (PDT) X-Received: by 10.49.72.225 with SMTP id g1mr4671535qev.36.1367290845420; Mon, 29 Apr 2013 20:00:45 -0700 (PDT) Path: ef9ni35280qab.0!nntp.google.com!s14no999299qam.0!postnews.google.com!glegroupsg2000goo.googlegroups.com!not-for-mail Newsgroups: comp.lang.ada Date: Mon, 29 Apr 2013 20:00:45 -0700 (PDT) In-Reply-To: Complaints-To: groups-abuse@google.com Injection-Info: glegroupsg2000goo.googlegroups.com; posting-host=189.110.14.106; posting-account=TRgI1QoAAABSsYi-ox3Pi6N-JEKKU0cu NNTP-Posting-Host: 189.110.14.106 References: <931385b2-3520-4d7a-b56f-6d0d0b06d467@googlegroups.com> <508e7264-46c3-4c53-94e6-6bb427fb3908@googlegroups.com> <7bb4c21a-be68-433e-a517-484798a8a687@googlegroups.com> <9f4422b8-7103-4acb-a770-63561f055008@googlegroups.com> User-Agent: G2/1.0 MIME-Version: 1.0 Message-ID: <751e142a-46d3-45da-8dba-e338c273eeeb@googlegroups.com> Subject: Re: AVR Usart send number string with no 'Image From: "Rego, P." Injection-Date: Tue, 30 Apr 2013 03:00:45 +0000 Content-Type: text/plain; charset=ISO-8859-1 Date: 2013-04-29T20:00:45-07:00 List-Id: On Friday, April 26, 2013 6:10:27 PM UTC-3, Shark8 wrote: > I rewrote it iteratively; I'm pretty sure an extended return doesn't require the second-stack so you should be fine. > declare > Subtype String_3 is String(1..3); > use Interfaces; > -- Because the secondary stack is disabled we cannot use either of > -- (a) recursion, or (b) unconstrained return-types. Therefore we > -- need to work both iteratively and with fixed-length strings. > Function To_String( Input : Unsigned_8 ) Return String_3 is > -- A temporary variable for manipulation, initialized to input. > Working : Unsigned_8 := Input; > begin > -- Extended return, we do not have to initialize any characters > -- because they will be in range '0'..'9' with leading zeros. > Return Result : String_3 do > -- We assign the digit it's proper value, based on its > -- position within the string. > For Digit in reverse Result'Range loop > Result(Digit):= Character'Val( > -- We add the mod 10 value of working > -- to the value of '0' to get the proper > -- digit-character. > Natural(Working mod 10) + > Character'Pos('0') > ); > -- We adjust our working-variable, by dividing it by 10. > Working:= Working / 10; > end loop; > end return; > End To_String; > -- Testing variable. > Temp : Natural := 4; > begin > -- Test > while Temp < 256 loop > Ada.Text_IO.Put_Line( To_String( Unsigned_8(Temp) ) ); > Temp:= Temp *2; > -- I want to end w/ 255, not 128. > Temp:= (if temp = 256 then 255 else temp); > end loop; > end; Thanks Shark8, it very worked! Also thanks for your comments.