Continue to Site

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.

simple assembler question

Status
Not open for further replies.

MathGeek

New Member
What is the difference between CONSTANT directive and EQU directive?

Likewise, what is the difference between VARIABLE and SET?


Do any of you know a good assembler tutorial with lots of examples?
(I found some from Microchip, but need more)

Thanks.
 
upand_at_them said:
This tutorial should answer all of your questions:

**broken link removed**

Mike

Actually, I came up with that quesiton after I read the third chapter of the tutorial. The tutorial (it seems to me) does not differentiate the directives (Constant and Equ) too much.
 
Equates are used to relate the hardware to software ..
In the example below every reference to the option register , which in this example is Equated to Hex 81 ,which is actually the location of the option register in the F88 ..
you could use the Hex Address of the option register ,when refering to the option register ,instead of the name , but it is much clearer when reading the program , to use an equate


as in
Code:
OPTION_REG                   EQU     H'0081' 
TRISA                        EQU     H'0085' 
TRISB                        EQU     H'0086' 
PIE1                         EQU     H'008C' 
PCON                         EQU     H'008E' 
PR2                          EQU     H'0092' 
TXSTA                        EQU     H'0098' 
SPBRG                        EQU     H'0099' 
EEDATA                       EQU     H'009A' 
ANSEL                        EQU     H'009B' 
CMCON                        EQU     H'009C' 
EECON2                       EQU     H'009D' 
ADRESL                       EQU     H'009E' 
ADCON1                       EQU     H'009F'
 
williB said:
Equates are used to relate the hardware to software ..
In the example below every reference to the option register , which in this example is Equated to Hex 81 ,which is actually the location of the option register in the F88 ..
you could use the Hex Address of the option register ,when refering to the option register ,instead of the name , but it is much clearer when reading the program , to use an equate


as in
Code:
OPTION_REG                   EQU     H'0081' 
TRISA                        EQU     H'0085' 
TRISB                        EQU     H'0086' 
PIE1                         EQU     H'008C' 
PCON                         EQU     H'008E' 
PR2                          EQU     H'0092' 
TXSTA                        EQU     H'0098' 
SPBRG                        EQU     H'0099' 
EEDATA                       EQU     H'009A' 
ANSEL                        EQU     H'009B' 
CMCON                        EQU     H'009C' 
EECON2                       EQU     H'009D' 
ADRESL                       EQU     H'009E' 
ADCON1                       EQU     H'009F'

Yes, I am aware of that....but then, "constant" cannot be used for register designation?
 
upand_at_them said:
I don't think I've ever used "CONSTANT," just "EQU." They seem to do the same thing.

Yes, as far as I'm aware all they do is a text substitution, so:

Code:
TRISA                        EQU     H'0085'

Means - "replace every occurance of TRISA in the text with H'0085'", CONSTANT is the same thing, it replaces the text of the constant with the value assigned to it.

You could do the same thing in a text editor by using search and replace before you compiled the file!.

Often in PIC assembler there are multiple ways to do the same thing, for example the hex value above can be written 0x0085.
 
Often in PIC assembler there are multiple ways to do the same thing, for example the hex value above can be written 0x0085.

This allows people migrating from a different processor or assembler to feel right at home with the same or similar directives in MPASM.

MPASM itself was not the first assembler of Microchip. I had used the PICALC assembler for the PIC16C5X family. Back then, the only way to represent the hex value was H'85'. This is still accepted by the current assembler as well as 0x85 and 85h.

When MPASM (made by a different company) replaced PICALC, it had to accept the syntax of the original assembler in addition to the ones used by new supplier.
 
Status
Not open for further replies.

Latest threads

New Articles From Microcontroller Tips

Back
Top