From: Shark8 <onewingedshark@gmail.com>
Subject: Re: AVR Usart send number string with no 'Image
Date: Fri, 26 Apr 2013 14:10:27 -0700 (PDT)
Date: 2013-04-26T14:10:27-07:00 [thread overview]
Message-ID: <db779ec0-cc14-41ed-bd8d-a839a8bf4f06@googlegroups.com> (raw)
In-Reply-To: <9f4422b8-7103-4acb-a770-63561f055008@googlegroups.com>
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;
next prev parent reply other threads:[~2013-04-26 21:10 UTC|newest]
Thread overview: 20+ messages / expand[flat|nested] mbox.gz Atom feed top
2013-04-25 1:27 AVR Usart send number string with no 'Image Rego, P.
2013-04-25 2:03 ` Shark8
2013-04-25 10:55 ` Rego, P.
2013-04-26 2:28 ` Rego, P.
2013-04-26 5:50 ` Simon Wright
2013-04-30 2:58 ` Rego, P.
2013-04-26 14:52 ` Shark8
2013-04-26 21:10 ` Shark8 [this message]
2013-04-30 3:00 ` Rego, P.
2013-04-25 4:54 ` rrr.eee.27
2013-04-25 10:58 ` Rego, P.
2013-05-01 20:35 ` Rego, P.
2013-05-01 21:00 ` Simon Wright
2013-05-01 22:07 ` Rego, P.
2013-05-01 22:30 ` Jeffrey Carter
2013-05-01 22:46 ` Rego, P.
2013-05-01 23:29 ` Dennis Lee Bieber
2013-05-01 22:32 ` Shark8
2013-05-01 23:00 ` Rego, P.
2013-05-01 23:09 ` Shark8
replies disabled
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox