Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

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
Most Helpful Member
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.

Latest threads

New Articles From Microcontroller Tips

Top