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.

Let's talk MPLAB directives

Status
Not open for further replies.
Alright -- I've been coding in PIC ASM for probably 6 or 7 months now. I still don't have a real clue what a lot of the MPLAB directives mean. I see them in sample code sometimes, and I'll occasionally read up on them, but mostly I just don't understand (seems like a trend with me, ha). I feel like I'm missing something by not understanding how to use these directives.

Here is some info I've copied from a tutorial -- with my questions below.

Code:
[B]DA[/B] Syntax: DA <expr> [, <expr2>, ...,<exprn>] This directive generates a packed 14-bit number representing two 7-bit ASCII characters. This is useful for storing strings in program memory.
Lett DA "abcdef" ; stores the string "abcdef" into memory 
; ... which can be accessed at label Lett

[B]DATA[/B] Syntax: DATA <expr> [, <expr2>, ...,<exprn>]
or DATA "<string>" [, "<string>", ...] Initialize one ore more words of program
memory with data. The data may be in the form of constants, relocatable or external labels or expressions of any of the previous. The data may also consist of ASCII character strings, enclosed in single quotes for one character or double quotes for strings.
Num DATA num+10 ; constants
Lett DATA "test string" ; text string
Char DATA ’N’ ; single character
Startp DATA start_of_prog ; relocatable label

[B]DB[/B] Syntax: DB <expr> [, <expr2>, ...,<exprn>] Reserve program memory words with packed 8-bit values. Multiple expressions continue to fill bytes consecutively until the end of expressions.

[B]DW[/B] Syntax: DW <expr> [, <expr2>, ...,<exprn>] Reserve program memory words for data initializing that space to specific values. Expressions can be literal strings and are stored as described
by the data directive.
Init DW 39, "diagnostic", (d_list*2+d_offset)
Stuff DB ’t’, 0x0f, ’e’, ’\n’

First off, all of these talk about reserving program memory. I take this to mean that this info is NOT stored in RAM, but is stored in the regular flash memory along with all the other code. Is this correct?

DA: Why is "storing strings in program memory" useful?

DATA: What the heck is a relocatable label? How would that be used?

DB: How is this different from what "DATA" can do?

DW: Okay - so we can initialize literal values. I'm having trouble seeing how this could be more useful that just using "MOLVW XX" at the right time in my code.

With any of these, do I have to give the "ORG" directive to specify a certain address before I give one of these directives.

Say I do this:
RANDOMLABEL DA "I am using a directive."
How is that now useful to me?

I've also seen "DE" (not listed above). It is only used for EEPROM, correct? Is it the EEPROM equivalent of "DA"?

Thanks guys.
 
hi,
When running MPLAB, use the Help option on the top Menu bar.
This will show a sub menu, select Topics.

From the displayed Help Topics Window select 'MPASM Assembler, OK

Type in the top text box, the Keyword , Directives

From the displayed list, double left click 'Directives Assembler'

From the Directives page, use the two hyperlinks, near the bottom.
 
Last edited:
Status
Not open for further replies.

Latest threads

New Articles From Microcontroller Tips

Back
Top