Hello Everyone, I am basically implementing the equivelent to a switch statement in C for my 8051 in assembly. There are multiple ways to implement a switch statement in assembly, however, I keep cornering myself into a statement like the following:
MOV A,CASE_LOCATION CJNE A,#CASE1_CONST,TRY_CASE2 LJMP CASE1
TRY_CASE2: CJNE A,#CASE2_CONST,TRY_CASE3 LJMP CASE2
and so on. The readability of this statement is bad, so I have devised a case statement of this nature
MOV A,CASE_LOCATION MOV R0,A ; Multiply A by 3 because LJMP is 3 bytes long RL A ADD A,R0 MOV DPTR,#CASE_TABLE JMP @A+DPTR
CASE_TABLE: LJMP CASE1 LJMP CASE2 LJMP CASE3
I am an not 100% sure this is correct, however, this thread is not to belabor the correctness of this switch statement syntax, but to discover the "best" way to implement a switch statement in 8051. I know finding the "best" switch statement is subjective but what are some ways people are doing implementing switch statements in 8051 assembly?
Thanks, Lloyd Rochester