Define.. want to understand

Status
Not open for further replies.

Ayne

New Member
Can we define a constant to our SFR like below???

&

supose i define a constant x = PORTB,3 like below
Code:
#define   x     PORTB,3
if i change the the value of x then the whole PORTB will effected or just bit 3 of PORTB will be effected??

Code:
movlw   b'10110110'
movwf   x
what will be the result ???
Code:
PORTB = 10110110
OR
Code:
PORTB.3 = 0
 
In your case, occurance of "x" will be replaced by "PORTB,3" before the source file is processed by assembler or compiler.

If you change the #define to other things, "x" will be substituted by other thing too.

You code does not make sense.
Code:
movlw   b'10110110'
movwf   x                ;<<<< wrong !!!

because it substituted into "movwf PORTB,3" and movwf moves 8-bit at a time.

Your remaining questions have nothing to do with the above ASCII replacement.
 
Essentially all define and equate do is a simple text substitution during assembly, as do those in the inc file. In your example, because it makes no sense, the assembler will generate an error.
 
Status
Not open for further replies.
Cookies are required to use this site. You must accept them to continue using the site. Learn more…