Re: a challenge
- From: "randyhyde@xxxxxxxxxxxxx" <randyhyde@xxxxxxxxxxxxx>
- Date: 8 Jan 2006 16:07:09 -0800
¬a\/b wrote:
> There are in this ng people that claim to have the best assembly
> syntax ever seen; people as Betov, Randall Hyde, Hutch, Herbert
> Kleebauer etc.
> This is the time to prove it ...
> I'm a poor beginner i have written no OS, no big program, nothing
> significant, but i want to know
> if your assembly language is the best assembly language ever seen
> or mine is it better:
> Can you write the same algo below in your favourite assembly syntax in
> the way it is more easy to read?
The problem is that you're assuming we can read the syntax of the code
you've written. While some of it is clear, other parts are not to
someone who does not know the language that you are using. Rather than
posting this code, why not just post the algorithm?
Of course, Rene ("Betov") doesn't do challenges. So you're just wasting
your breath, there.
As for HLA, here's the "uToEnglish" function from the HLA Standard
Library:
unit ConvUnit;
#include( "conversions.hhf" );
//#include( "stdout.hhf" );
/************************************************/
/* */
/* _utoEng- */
/* */
/* Converts an unsigned number to a string */
/* containing the English equivalent of that */
/* number. E.g., 25 becomes "twenty-five". */
/* */
/* Inputs: */
/* */
/* u: Number to convert. */
/* dest: String to store result into. */
/* */
/* Note: the destination string must be large */
/* enough to hold the result. The largest */
/* possible string probably needs no more than */
/* about 128 characters (3,777,777,777). */
/* */
/************************************************/
// Recursive procedure that does the
// actual conversion after the main
// "utoEng" function sets up appropriate
// register values.
procedure _utoEng; @nodisplay; @noframe;
begin _utoEng;
// All but the last of the following
// code sections wind up doing a division,
// so zero extend EAX into EDX at this
// point just to save some code.
xor( edx, edx );
// If the value is greater than a billion,
// pick off the billion's digit (there can
// be only one), convert it to English,
// append "billion" to that string, and
// recursively call this function again
// if the remainder isn't zero.
if( eax >= 1_000_000_000 ) then
mov( 1_000_000_000, ebx );
div( ebx, edx:eax );
str.cat( LessThan20[ eax*4 ], edi );
if( edx ) then
str.cat( " billion ", edi );
mov( edx, eax );
_utoEng();
else
str.cat( " billion", edi );
endif;
// If the value is greater than a million,
// pick off the millions digits (there can
// be as many as three) and call _utoEng
// recursively to convert it to a string
// between one and 999. Then append
// the string "million" to the end of that
// conversion. Finally, if the remainder
// is not zero, all this routine recursively
// to handle the remainder.
elseif( eax >= 1_000_000 ) then
mov( 1_000_000, ebx );
div( ebx, edx:eax );
push( edx );
_utoEng();
pop( edx );
if( edx ) then
str.cat( " million ", edi );
mov( edx, eax );
_utoEng();
else
str.cat( " million", edi );
endif;
// If the value is greater than 1,000, pick
// pick off the thousands digits (there can
// be as many as three) and call _utoEng
// recursively to convert it to a string
// between one and 999. Then append
// the string "thousand" to the end of that
// conversion. Finally, if the remainder
// is not zero, all this routine recursively
// to handle the remainder.
elseif( eax >= 1_000 ) then
mov( 1_000, ebx );
div( ebx, edx:eax );
push( edx );
_utoEng();
pop( edx );
if( edx ) then
str.cat( " thousand ", edi );
mov( edx, eax );
_utoEng();
else
str.cat( " thousand", edi );
endif;
// If the value is greater than 100, pick
// of the hundred's digit (there can be only
// one) and use this as an index into the
// LessThan20 table to select the appropriate
// string to use. Concatenate "hundred" to
// the result and then call _utoEng recursively
// to handle the remainder (if it is not zero).
elseif( eax >= 100 ) then
mov( 100, ebx );
div( ebx, edx:eax );
str.cat( LessThan20[ eax*4 ], edi );
if( edx ) then
str.cat( " hundred ", edi );
mov( edx, eax );
_utoEng();
else
str.cat( " hundred", edi );
endif;
// For values between 20 & 99, strip the
// tens digit and print the appropriate
// text. If the one's digit is not zero,
// concatenate "-" and the corresponding
// string for the one's digit to the end of
// the string.
elseif( eax >= 20 ) then
mov( 10, ebx );
div( ebx, edx:eax );
if( edx ) then
str.cat( Tens[ eax*4 ], edi );
str.cat( "-", edi );
str.cat( LessThan20[ edx*4 ], edi );
else
str.cat( Tens[ eax*4 ], edi );
endif;
// If all we've got left is a value in the
// range 0..19, simply copy the corresponding
// string to the end of the string we're
// building.
else
str.cat( LessThan20[ eax*4 ], edi );
endif;
ret();
end _utoEng;
end ConvUnit;
Cheers,
Randy Hyde
.
- Follow-Ups:
- Re: a challenge
- From: Frank Kotler
- Re: a challenge
- References:
- a challenge
- From: ¬a\\/b
- a challenge
- Prev by Date: Re: a challenge
- Next by Date: Re: anyone can suggest some good books to me?
- Previous by thread: Re: a challenge
- Next by thread: Re: a challenge
- Index(es):
Relevant Pages
|