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

Back to Subject List

Old thread has been locked -- no new posts accepted in this thread
???
12/20/01 10:23
Read: times


 
#17856 - RE: case statement using assy
Lance's answer is clear and precise. Even so I'd like to include an example. If you want to write an equivalent to the switch-case construction, the fastest solution is the jump table. This option is specially suitable if the test values are a sequential list:

case 0:
(...)
break;
case 1:
(...)
break;

There is a special instruction for this purpose:

jmp @a+dptr

The switch statement can be implemented in the following way:

mov dptr,#jumptable
mov a,switchvar
rl a ; =2*a
jmp @a+dptr
; the next instruction is a common return point after the switch/case
common:
(...)

jumptable:
ajmp case0 ; 2 bytes per instruction
ajmp case1
(...)

case0:
; your code for case 0
ajmp common ; "equivalent to break"

case1:
(...)

If you plan to use ljmp's you must provide more room for each entry in the jump table. You can place two RL A instructions instead of one.

Regards,

Alfredo del Rio.


List of 9 messages in thread
TopicAuthorDate
case statement using assy            01/01/70 00:00      
RE: case statement using assy            01/01/70 00:00      
RE: case statement using assy            01/01/70 00:00      
RE: case statement using assy            01/01/70 00:00      
RE: case statement using assy            01/01/70 00:00      
RE: case statement using assy            01/01/70 00:00      
RE: case statement using assy - spencer            01/01/70 00:00      
RE: case statement using assy            01/01/70 00:00      
RE: case statement using assy            01/01/70 00:00      

Back to Subject List