Welcome, Guest. Please login or register.

Author Topic: Programming question! :)  (Read 3310 times)

Description:

0 Members and 1 Guest are viewing this topic.

Offline SamuraiCrow

  • Hero Member
  • *****
  • Join Date: Feb 2002
  • Posts: 2280
  • Country: us
  • Gender: Male
    • Show all replies
Re: Programming question! :)
« on: April 16, 2012, 04:33:42 PM »
Quote from: bloodline;688783
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: [Select]


_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


But I want to write this in C... Suffice to say the actual list is much larger and CPU time is at a premium, is there any way I can write it without using Goto?

Code: [Select]

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;
}

This is an exact conversion of the Assembly code you gave and it doesn't use any goto statements.