# how to do case select in ASM??

Status
Not open for further replies.

#### belinda_sg

##### New Member
in c, we have if or case select to select different cases...

but how can we do it in assembly?

especially for the PIC programming?

can anyone give me some suggestion?
thx...

#### Nigel Goodwin

##### Super Moderator
belinda_sg said:
in c, we have if or case select to select different cases...

but how can we do it in assembly?

especially for the PIC programming?

can anyone give me some suggestion?
thx...

You do it with a series of subtractions and tests.

I'm presuming you are talking about the 4 bit A2D result you asked about in another thread, if so there's an easier and faster way to do it.

As you have only 16 possible results (with 4 bits) you could use a jump table. This works exactly like a lookup table, except instead of RETLW lines it uses GOTO's instead.

#### kinjalgp

##### Active Member
Instead of subtraction, you can also use XOR function to test if variable = constant expression.

#### motion

##### New Member
Here's a PIC16 code sample:

Code:
; On entry, W reg contains the switch value
;
SWITCH:
movwf	TEMP	; Save to a temporary register
;
movlw	CASE1_VAL
subwf	TEMP,W
skpnz
goto	CASE1
;
movlw	CASE2_VAL
subwf	TEMP,W
skpnz
goto	CASE2
;
return
CASE1:
return
CASE2:
return

Status
Not open for further replies.

Replies
37
Views
1K
Replies
8
Views
698
Replies
4
Views
437
Replies
36
Views
1K
Replies
5
Views
430