PDA

View Full Version : How to display large numbers



Peter1960
- 24th March 2006, 01:42
Hi,

I have used the 32 bit asm multiply routine and have got a number larger than 16 bits (of course!!)

Now i want to display this number but it wont !!

OK..

The number is 317440

The numbers displayed are

4 55296

4 is the high byte number = 262144
55296 is the low byte number = 55296

add these togheter you get 317440, correct answer but wrong display...

debug #(hibyte), # (lobyte)

any suggestions ?

thnks

Pete

paul borgmeier
- 24th March 2006, 14:08
Interesting problem ... although there must be a cleaner way, the below works for YOUR specific numbers. The below is not ready for plug and chug with any double word but should help YOU get headed in the right direction. Fun stuff!

Lo_word var word
Hi_word var word
X_temp var word

Digs var byte [6]

Lo_word = 55296 ' Low word
Hi_word = 4 ' High Word (= 4 * 65536)

'**************************
'Find 3 low digits of your 6 digit decimal number

X_temp = Hi_Word * 536 + Lo_word ' = 57440

' take 4*65536+55296 = 4*(6200+536)+55296 = 4*62000+4*536+55296
' the 4*62000 term does not contribute to the low 3 digits so leave it out

Digs[0]=X_temp Dig 0 ' = 0
Digs[1]=X_temp Dig 1 ' = 4
Digs[2]=X_temp Dig 2 ' = 4

'**************************
'Find 3 High digits of your 6 digit decimal number

X_Temp = Hi_Word * 2 ' = 8
X_Temp = 32768 * X_temp ' = 262144
X_Temp = Div32 100 ' = 2621
X_Temp = X_temp + (Lo_word/100) ' = 3173

Digs[3]=X_temp Dig 1 ' = 7
Digs[4]=X_temp Dig 2 ' = 1
Digs[5]=X_temp Dig 3 ' = 3

'**************************
'Display (change to meet your needs)

' for X_temp = 5 to 0 step -1
' Debug Dec Digs[X]
' next X_temp

END

Good Luck,

Paul Borgmeier
Salt Lake City, Utah
USA

paul borgmeier
- 24th March 2006, 15:54
Opps - on the comment in the above code snippet ....

is:
' take 4*65536+55296 = 4*(65000+536)+55296 = 4*65000+4*536+55296
' the 4*65000 term does not contribute to the low 3 digits so leave it out

was:
' take 4*65536+55296 = 4*(6200+536)+55296 = 4*62000+4*536+55296
' the 4*62000 term does not contribute to the low 3 digits so leave it out


I need more coffee - paul

BigWumpus
- 26th March 2006, 23:17
OK,

32-bit-arithemtik,
sometimes I'm happy to have learned the basics of our job (on a pdp/8 with 12-bit-words an silly switches and lamps on the front).

Div-by-10 ... uuuh ... I feel sleepy!

$7FFFFFFF is decimal 2147483647 .... uuuh, the big one !

I think, you will deal with 7-count numbers....
Just look, if the number is bigger then 999999:

Flag=0
if High_Word>$F Then Flag=1
if High_Word=$F AND Low_Word>$423F Then Flag=1

If it is bigger, count how often by subtracting 1000000 !

Ct=0
If Flag Then
Repeat
If Low_Word<$4240 Then High_Word=High_Word-1
Low_Word=Low_Word-$4240:Ct=Ct+1
[...] copy **** from above
Until Flag=0
Endif

You got an digit ! Just Store or print it ! (LCDWRITE "0"+Ct)
Multiply the rest by 10 !

Gosub Rotate32 (x2)
High_Copy=High_Byte:Low_Copy=Low_Byte
Gosub Rotate32:Gosub Rotate32 (all together x8)
High_Word=High_Word+High_Copy
If Low_Word.15 AND Low_Copy.15 Then High_Word=High_Word+1:Low_Word.15=0:Low_Copy.15=0
Flag=Low_Word.15 or Low_Copy.15
Low_Word=Low_Word+Low_Copy:If Flag AND (Low_Word.15=0) Then High_Word=High_Word+1

Rotate32:
High_Word=High_Word<<1:If Low_Word.15 Then High_Word.0=1
Low_Word=Low_Word<<1:Return

uuuuh ... with assembler its much smoother because of the carry-flag.


Repeat it seven times !
Go sleep!