Electronic Projects, forums and more.

Go Back   Electronic Circuits Projects Diagrams Free > Electronics Categories > Micro Controllers


Micro Controllers Discuss all aspects of micro controllers - building them, coding them, etc. All controllers are welcome - PIC, BASIC, Z8 Encore!, etc.

Reply
 
LinkBack Thread Tools Display Modes
Old 19th February 2004, 04:25 AM   (permalink)
Default how to do case select in ASM??

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...
belinda_sg is offline  
Old 19th February 2004, 07:05 AM   (permalink)
Default Re: how to do case select in ASM??

Quote:
Originally Posted by belinda_sg
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.
Nigel Goodwin is online now  
Old 19th February 2004, 06:00 PM   (permalink)
Default

Instead of subtraction, you can also use XOR function to test if variable = constant expression.
__________________
"There is no way to peace, peace is the way!"
kinjalgp is offline  
Old 19th February 2004, 11:17 PM   (permalink)
Default

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
__________________
"Having to do with Motion Control"
motion is offline  
Reply

Bookmarks

Thread Tools
Display Modes





All times are GMT. The time now is 09:23 PM.


Electronic Circuits  |  Learning Electronics
Powered by vBulletin® Version 3.7.0
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.

eXTReMe Tracker