Email: Password: Remember Me | Create Account (Free)

Back to Subject List

Old thread has been locked -- no new posts accepted in this thread
???
01/12/08 07:36
Modified:
  01/12/08 07:43

Read: times


 
#149349 - One way to do this
Responding to: ???'s previous message
I know the rest of the forum will like this ;)

So You want to make a thing that behaves like C switch statement but do it without a long row of compare statements.

Here goes:

The code:
RETADR_H         EQU      0Dh
RETADR_L         EQU      0Eh

                 MOV      A,#3*2            ; Each LJMP instruction is 3 bytes long
                 LCALL    SWITCH_THING
                 LJMP     ROUTINE_FOR_0
                 LJMP     ROUTINE_FOR_1
                 LJMP     ROUTINE_FOR_2     ; <- Returns here
                 LJMP     ROUTINE_FOR_3
                 ...
                 LJMP     ROUTINE_FOR_85    ; <- EDIT: Only 85


SWITCH_THING:    POP      RETADR_H          ; Get return address from stack
                 POP      RETADR_L          ; Was pushed HI byte last
                 ADD      A,RETADR_L
                 MOV      RETADR_L,A
                 ADDC     A,RETADR_H
                 MOV      RETADR_H,A
                 PUSH     RETADR_L          ; Put the modified address back to stack
                 PUSH     RETADR_H
                 RET                        ; Do a return to the new modified address


List of 32 messages in thread
TopicAuthorDate
Where can I ask newbie questions?            01/01/70 00:00      
   There is no such thing as a newbie question            01/01/70 00:00      
      the question            01/01/70 00:00      
         jump table            01/01/70 00:00      
            WOW, this is what I'm looking for!            01/01/70 00:00      
               *Very* Dangerous game!            01/01/70 00:00      
                  Agree with Dangerous            01/01/70 00:00      
                  PC            01/01/70 00:00      
               A and ACC            01/01/70 00:00      
                  ACC            01/01/70 00:00      
                     Different ways of getting to the same thing            01/01/70 00:00      
                        NO!            01/01/70 00:00      
                           OK, to put it another way...            01/01/70 00:00      
               jump table            01/01/70 00:00      
         the simple and stupid way...            01/01/70 00:00      
   One way to do this            01/01/70 00:00      
      Compare with JMP @A+PC            01/01/70 00:00      
         Yes there is            01/01/70 00:00      
         JMP @A+PC?            01/01/70 00:00      
            Oops            01/01/70 00:00      
   FAQ?            01/01/70 00:00      
      I think...            01/01/70 00:00      
         That's fine            01/01/70 00:00      
         English,            01/01/70 00:00      
   Newbie questions            01/01/70 00:00      
      Steve, I disagree            01/01/70 00:00      
   One question at a time            01/01/70 00:00      
   Agree to one question at time...            01/01/70 00:00      
      manipulating PC            01/01/70 00:00      
         PC            01/01/70 00:00      
   isnt an abuse ask more questions?            01/01/70 00:00      
      You said it yourself - start a new thread!            01/01/70 00:00      

Back to Subject List