Masking Upper Nibble

Status
Not open for further replies.

Suraj143

Active Member
Hi I need to mask the upper nibble & must not do any harm to the lower nibble.

But this code never work.

Code:
	movf	Data,W
	andlw	b'11110000'
	iorwf	PORTB,F


But this code works but corrupting lower nibble.

Code:
	movf	Data,W
	andlw	b'11110000'
	movwf	PORTB,F
 
Hi I need to mask the upper nibble & must not do any harm to the lower nibble.

But this code works but corrupting lower nibble.
Code:
	movf	Data,W
	andlw	b'11110000'
	movwf	PORTB,F
That's because you should use AND to clear, or mask, the upper nibble - not the lower nibble. Like this:
Code:
	andlw	b'00001111'
This will zero out the upper nibble and leave the lower nibble exactly the way it was.
 
Last edited:
Do you wish to transfer the upper nibble of Data to the upper nibble of PORTB without disturbing the lower nibble in either?
 
Exactly this is what I need to do.
Then first move Data to a temp variable or W and mask the lower nibble. Then mask the upper nibble of PORTB (maybe move it to a temporary variable first). Then OR them together.

Maybe there's a simpler way?
 
Last edited:
Then first move Data to a temp variable or W and mask the lower nibble. Then mask the upper nibble of PORTB (maybe move it to a temporary variable first). Then OR them together.

Maybe there's a simpler way?

Code:
	movf	Data,W
	andlw	b'00001111'
	????	????
	iorwf	PORTB,F
 
Code:
	movf	Data,W
	andlw	b'11110000'
	movwf	temp1
	movf	PORTB,w
	andlw	b'00001111'
	iorwf	temp1,w
	movwf	PORTB
Hmm... Is that right? Just quickly banged it out. Can't test it quickly.
 
Code:
	movf	Data,W
	andlw	b'11110000'
	movwf	temp1
	movf	PORTB,w
	andlw	b'00001111'
	iorwf	temp1,w
	movwf	PORTB
Hmm... Is that right? Just quickly banged it out. Can't test it quickly.

OK thanks for your help.It will work.
 
Status
Not open for further replies.
Cookies are required to use this site. You must accept them to continue using the site. Learn more…