??? 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 |