|
Register or have you forgotten your password?
|
|
|
| Other Operating Systems This forum is to allow our members to discuss other (non-Amiga-related) operating systems. |
![]() |
|
|
Thread Tools | Display Modes |
|
|
|
|
#1 | ||||||||
|
Master Sock Abuser
|
I have a list that I want to compare a value against to determine the value's "rank", the problem is that once I have determined the rank I wish to end the search... In ASM this is easy (please bare with my half remembered 68k):
Code:
_start move.l _number,d0
cmpi.l #4185,d0
blt.s _case4184
cmpi.l #4507,d0
blt.s _case4507
cmpi.l #4883,d0
blt.s _case4883
cmpi.l #5327,d0
blt.s _case5327
move.l 0,d0
_break
rts
_case4185
move.l #4,d0
jmp _break
_case4507
move.l #3,d0
jmp _break
_case4883
move.l #2,d0
jmp _break
_case5327
move.l #1,d0
jmp _break
__________________
My iPhone Game: Puny Humans - http://itunes.apple.com/gb/app/puny-...362230281?mt=8 |
||||||||
|
|
|
|
|
#2 | ||||||||
|
Defender of the Faith
![]()
|
Try using a switch statement. It should produce code very similar to what you have posted, usually using a jump table but check the asm output to make sure it's acceptable.
Also, you might want to consider examining your algorythmic boundaries! (j/k) |
||||||||
|
|
|
|
|
#3 | |||||||||
|
Defender of the Faith
![]()
Join Date: May 2010
Location: Dundee, OR
Posts: 1,621
|
Quote:
|
|||||||||
|
|
|
|
|
#4 | |||||||||
|
Master Sock Abuser
|
Quote:
__________________
My iPhone Game: Puny Humans - http://itunes.apple.com/gb/app/puny-...362230281?mt=8 |
|||||||||
|
|
|
|
|
#5 | |||||||||
|
Cult Member
![]()
Join Date: Oct 2009
Posts: 553
|
Quote:
If you can have an array of threshold values, then you might still have your table. How big is the largest value? |
|||||||||
|
|
|
|
|
#6 | |||||||||
|
Master Sock Abuser
|
Quote:
The largest value is 60,000 (a lookup table is totally out of the question)
__________________
My iPhone Game: Puny Humans - http://itunes.apple.com/gb/app/puny-...362230281?mt=8 |
|||||||||
|
|
|
|
|
#7 | ||||||||||
|
Cult Member
![]()
Join Date: Oct 2009
Posts: 553
|
Quote:
Quote:
Please provide us with some more information here, because you've left out crucial details. |
||||||||||
|
|
|
|
|
#8 | ||||||||
|
Cult Member
![]()
Join Date: Oct 2009
Posts: 553
|
How long is that list exactly? If it's not too large you can use a table, which would certainly be the fastest way.
|
||||||||
|
|
|
|
|
#9 | |||||||||
|
Premium Member
|
Quote:
Code:
int test(num)
{
if (num<4185)return 4;
if (num<4507)return 3;
if (num<4883)return 2;
if (num<5327)return 1;
return 0;
}
|
|||||||||
|
|
|
|
|
#10 | |||||||||
|
Master Sock Abuser
|
Quote:
hahahah
__________________
My iPhone Game: Puny Humans - http://itunes.apple.com/gb/app/puny-...362230281?mt=8 |
|||||||||
|
|
|
|
|
#11 | |||||||||
|
Technoid
![]()
Join Date: Mar 2002
Location: Belgium
Posts: 498
|
Quote:
Code:
rank =
(num<4185) ? 4 :
(num<4507) ? 3 :
(num<4883) ? 2 :
(num<5327) ? 1 :
0;
Staf.
__________________
Trust me... I know what I'm doing |
|||||||||
|
|
|
|
|
#12 | ||||||||
|
Master Sock Abuser
|
Ahhh! Good call, I'm quite comfortable with usig a function, but I won't forget this either!! Many thanks for your help
__________________
My iPhone Game: Puny Humans - http://itunes.apple.com/gb/app/puny-...362230281?mt=8 |
||||||||
|
|
|
|
|
#13 | ||||||||
|
Off to greener pastures
Join Date: Jul 2009
Posts: 1,058
|
Threads like this are what makes A.org great. People helping people out.
|
||||||||
|
|
|
|
|
#14 | ||||||||
|
Master Sock Abuser
|
There are loads of great programmer on A.org... Odd actually that there isn't a dedicated forum for programming issues?
__________________
My iPhone Game: Puny Humans - http://itunes.apple.com/gb/app/puny-...362230281?mt=8 |
||||||||
|
|
|
|
|
#15 | ||||||||
|
Kindred of Babble-on
![]()
|
Actually, comparing against an array uses less RAM all in all (just the values and the loop, you save the space of all but one cmp and blt ops minus loop ops). On a somewhat caching CPU it should also perform better since the loop needs only be fetched once and then just the array values get read - the slowest is always the memory. Without cache your approach will be faster, saving the loop overhead.
Also depends on the indexing range the CPU is capable of, of course... You could also combine both methods with a larger loop (did that once on a 6502 to save the few cycles I needed). |
||||||||
|
|
|
![]() |
| Bookmarks |
| Tags |
| programming , question |
| Thread Tools | |
| Display Modes | |
|
|