bitwise tricks for logic operations or......

Status
Not open for further replies.

zhaniko93

New Member
Hello.
I have been working on a project where I had to write a code in assembly which in c++ looked like: if(a && b && c) and couldn't solve it. can any 1 help me how to write a code in assemly for triple AND without using 3 level of stack and a lot of code of course
 
Code:
Wait_Loop	movf	A,W
		andwf	B,W
		andwf	C,W
		btfsc	STATUS,Z
		goto	Wait_Loop	; result is zero
		;
		;			; ANDed result is not zero
Code:
Wait_Loop	movf	Data,W
		andlw	b'00010101'	; AND only bit 0,2,4
		btfsc	STATUS,Z
		goto	Wait_Loop	; result is zero
		;
		;			; ANDed result is not zero
 
If they are bits then,
Code:
	movlw	1
	btfss	a,0
	movlw	0
	btfss	b,0
	movlw	0
	btfss	c,0
	movlw	0
or, if bytes,
Code:
	movlw	1
	movf	a,f
	btfsc	STATUS,Z
	movlw	0
	movf	b,f
	btfsc	STATUS,Z
	movlw	0
	movf	c,f
	btfsc	STATUS,Z
	movlw	0

The result will be in W.

Mike.
 
To understand the code above you need to learn what the assembly instructions do. Study one of the tutorials in this thread to get a better understanding.

Mike.
 
No no, I understand everything well I just want to learn more about such tricks but I know very well what do each of the instructions do
 
No no, I understand everything well I just want to learn more about such tricks but I know very well what do each of the instructions do

They aren't 'tricks' they are just standard useage of the instructions - there are only a small number of instructions to learn, which is why PIC assembler is so easy for beginners.
 
It's all logic You can learn a lot reading mplab mpasm help files. You just got to think like a pic. How can i do that with a 0 or 1 And Mike and Nigel are both real smart cats I would just like to no half what they Know. I learned a lot from both of them.

I'm getting ready to learn a bunch more I start college January 10 full time first thing I have to learn is how to write. They said I was horrible. I thought that was funny I know I'm not a good writer. But I scored some what good seeing not all classes are refreshers. And one is for my college major I get to do some programing my fist year even if it will be C++

zhaniko93 maybe we both learn some English this year and be great writers Ps. I hope you like the pickit2 clone you'll have about January 10th. Good luck with your coding. Oh read about logic chips and how they work and asm will be easier to get a grasp of.

Great stuff to read attachment
 

Attachments

  • great_stuff.JPG
    130 KB · Views: 211
Last edited:
Hey Burt,

Good luck at college. However, you're a quick learner so shouldn't need luck. Keep us posted on how you're doing.

Mike.
 
Status
Not open for further replies.
Cookies are required to use this site. You must accept them to continue using the site. Learn more…