|
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 | ||||||||
|
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.
|
||||||||
|
|
|
|
|
#4 | |||||||||
|
Defender of the Faith
![]()
Join Date: May 2010
Location: Dundee, OR
Posts: 1,621
|
Quote:
|
|||||||||
|
|
|
|
|
#5 | |||||||||
|
Master Sock Abuser
|
Quote:
__________________
My iPhone Game: Puny Humans - http://itunes.apple.com/gb/app/puny-...362230281?mt=8 |
|||||||||
|
|
|
|
|
#6 | |||||||||
|
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? |
|||||||||
|
|
|
|
|
#7 | |||||||||
|
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 |
|||||||||
|
|
|
|
|
#8 | |||||||||
|
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;
}
|
|||||||||
|
|
|
|
|
#9 | |||||||||
|
Master Sock Abuser
|
Quote:
hahahah
__________________
My iPhone Game: Puny Humans - http://itunes.apple.com/gb/app/puny-...362230281?mt=8 |
|||||||||
|
|
|
|
|
#10 | ||||||||||
|
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. |
||||||||||
|
|
|
|
|
#11 | |||||||||
|
Master Sock Abuser
|
Quote:
and Sam Crow has poked my brain and given me exactly the solution I was trying to think of... Funny how I could see it in 68k Asm (that haven't used for 15 years), but not in C
__________________
My iPhone Game: Puny Humans - http://itunes.apple.com/gb/app/puny-...362230281?mt=8 |
|||||||||
|
|
|
|
|
#12 | |||||||||
|
Cult Member
![]()
Join Date: Oct 2009
Posts: 553
|
Quote:
|
|||||||||
|
|
|
|
|
#13 | |||||||||
|
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 |
|||||||||
|
|
|
|
|
#14 | ||||||||
|
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 |
||||||||
|
|
|
|
|
#15 | ||||||||
|
Off to greener pastures
Join Date: Jul 2009
Posts: 1,056
|
Threads like this are what makes A.org great. People helping people out.
|
||||||||
|
|
|
![]() |
| Bookmarks |
| Tags |
| programming , question |
| Thread Tools | |
| Display Modes | |
|
|