English Amiga Board


Go Back   English Amiga Board > Coders > Coders. Asm / Hardware

 
 
Thread Tools
Old 06 March 2014, 14:30   #1
h0ffman
Registered User
 
Join Date: Aug 2008
Location: Salisbury
Posts: 744
Working out a decimal percentage for display

Me again!

I'm trying to work out the percentage difference between two numbers so that it can be displayed as, for example, +%040 on screen.

I've already got a the decimal conversion, the problem is working out the actual value.

I tried the following..

Quote:
move.w #120,d0
move.w #90,d1
divu d1,d0
on a calculator it comes out as 1.333333... which is a 33% increase. However i'm simply left with 1 and the remainder in the upper half of the data register.

It also needs to deal with the calculation the other way, i.e. show a negative percentage.

Any help would be awesome.
h0ffman is online now  
Old 06 March 2014, 15:52   #2
demolition
Unregistered User
 
demolition's Avatar
 
Join Date: Sep 2012
Location: Copenhagen / DK
Age: 43
Posts: 4,190
If you want two decimals, you could do the following in pseudo-code using integer math:

If Num1>Num2
Result = Num1*100 / Num2 - 100
else
Result = -(Num2*100 / Num1 - 100)

Last edited by demolition; 06 March 2014 at 15:55. Reason: Parenthesis error
demolition is offline  
Old 06 March 2014, 16:00   #3
hooverphonique
ex. demoscener "Bigmama"
 
Join Date: Jun 2012
Location: Fyn / Denmark
Posts: 1,624
move #original value,d1
move #new value, d0
sub d1, d0
muls #100,d0
divs d1,d0


if you do that with your example above, d0 will now be -25 (90 is 120-25%).
hooverphonique is offline  
Old 06 March 2014, 16:04   #4
h0ffman
Registered User
 
Join Date: Aug 2008
Location: Salisbury
Posts: 744
Quote:
Originally Posted by hooverphonique View Post
move #original value,d1
move #new value, d0
sub d1, d0
muls #100,d0
divs d1,d0


if you do that with your example above, d0 will now be -25 (90 is 120-25%).
Perfect!! thats actually the same data registers I'm using too!!
h0ffman is online now  
Old 06 March 2014, 16:04   #5
demolition
Unregistered User
 
demolition's Avatar
 
Join Date: Sep 2012
Location: Copenhagen / DK
Age: 43
Posts: 4,190
Quote:
Originally Posted by hooverphonique View Post
if you do that with your example above, d0 will now be -25 (90 is 120-25%).
True, my example was faulty as it did not calculate that correctly, so ignore what I wrote.
demolition is offline  
Old 06 March 2014, 16:07   #6
hooverphonique
ex. demoscener "Bigmama"
 
Join Date: Jun 2012
Location: Fyn / Denmark
Posts: 1,624
Quote:
Originally Posted by h0ffman View Post
Perfect!! thats actually the same data registers I'm using too!!
Yeah.. I did that on purpose
hooverphonique is offline  
Old 07 March 2014, 09:49   #7
h0ffman
Registered User
 
Join Date: Aug 2008
Location: Salisbury
Posts: 744
Well this has been a learning experience, only just realised there is a MULS and MULU! Signed and unsigned. I really need to read the 68000 manual again!

All good now, got it working
h0ffman is online now  
 


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools

Similar Threads
Thread Thread Starter Forum Replies Last Post
Better display Ronnie_ASA support.WinUAE 1 01 March 2014 19:50
External Disk Drive working and not working fc.studio support.Hardware 12 10 August 2009 03:04
floppy df0 working / not working Dave_wb support.Hardware 3 07 January 2009 09:11
Hex to Decimal -Rob- Coders. General 8 21 June 2006 19:22
Display problem abelthorne support.WinUAE 1 25 November 2003 13:25

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +2. The time now is 00:56.

Top

Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2024, vBulletin Solutions Inc.
Page generated in 0.07726 seconds with 13 queries