Exact match. Not showing close matches.
PICList
Thread
'[PIC]: MPASM include files'
2001\04\05@184539
by
David Cary
|
Dear Pic'ers,
I've found lots of very clever little PIC assembler fragments on
http://piclist.org/ . Now I'm looking for advice on how to structure an entire
project.
I'm getting unexpected errors from MPASM now that I've split up my project into
several files. Maybe I just need to learn the ``Assembly Way'' of doing things.
I'm used to the ``C Way'' of breaking up a program into several files, as
explained in the C FAQ:
http://www.faqs.org/faqs/C-faq/faq/
<blockquote>
1.7: What's the best way to declare and define global variables
and functions?
A: First, though there can be many "declarations" (and in many
translation units) of a single "global" (strictly speaking,
"external") variable or function, there must be exactly one
"definition". (The definition is the declaration that actually
allocates space, and provides an initialization value, if any.)
The best arrangement is to place each definition in some
relevant .c file, with an external declaration in a header
(".h") file, which is #included wherever the declaration is
needed. The .c file containing the definition should also
#include the same header file, so that the compiler can check
that the definition matches the declarations.
</blockquote>
Unfortunately, I seem to get a lot of errors like
Error[115] C:\DAVID\GRAPHI~1\LCD_CO~1\TEST.ASM 4 : Duplicate label
("times1.5" or redefining symbol that cannot be redefined)
Error[115] C:\DAVID\GRAPHI~1\LCD_CO~1\TEST.ASM 5 : Duplicate label ("ACC0"
or redefining symbol that cannot be redefined)
The odd thing is, MPASM claims there is a "duplicate", yet it only shows an
error in one place. When I accidentally make ``real'' duplicates, MPASM usually
shows me both places. Is this a bug in MPASM ?
I seem to get some kind of error no matter how I tweak my ``test.inc'' file. If
I replace ``EXTERN'' with ``GLOBAL'' in that file, I get
Error[113] C:\DAVID\GRAPHI~1\LCD_CO~1\MAIN.ASM 38 : Symbol not previously
defined (times1.5)
Error[113] C:\DAVID\GRAPHI~1\LCD_CO~1\TEST.INC 17 : Symbol not previously
defined (ACC0)
.
Here's my 3 test files: test.inc, test.asm, main.asm
; test.inc
; subroutines
EXTERN times1.5
; parameters for subroutines (registers)
EXTERN ACC0
EXTERN ACC1
EXTERN TEMP0
EXTERN TEMP1
; end file test.inc
; test.asm
INCLUDE test.inc ; module definition file
shared_math_stuff UDATA_shr
ACC0 res 1
ACC1 res 1
TEMP0 res 1
TEMP1 res 1
test_subs CODE
times1.5:
; ACC = ACC * 1.5
; Temp = TEMP
; ACC size = 8 bits
; Error = 0.5 %
; Bytes order = little endian
; Round = yes
;
; ALGORITHM:
; Clear accumulator
; Add input * 2 to accumulator
; Add input * 1 to accumulator
; Shift accumulator right (LSb to carry)
; If carry set, increment accumulator
; Move accumulator to result
; Approximated constant: 1.5, Error: 0 %
; Input: ACC0, 8 bits
; Output: ACC0 .. ACC1, 9 bits
; Code size: 20 instructions
;
;copy accumulator to temporary
movf ACC0, w
movwf TEMP0
;shift temporary left 1 times
clrc
rlf TEMP0, f
clrf TEMP1
rlf TEMP1, f
;add temporary to accumulator
clrf ACC1
movf TEMP0, w
addwf ACC0, f
movf TEMP1, w
skpnc
incfsz TEMP1, w
addwf ACC1, f
;shift accumulator right once and
;increment if carry set
rrf ACC1, f
rrf ACC0, f
skpc
goto no_inc
incf ACC0, f
skpnz
incf ACC1, f
no_inc
; Generated by http://www.piclist.com/cgi-bin/constdivmul.exe (November 17, 2000
version)
; Thu Apr 05 17:18:58 2001 GMT
END
; end file test.asm
; main.asm
LIST P=PIC16F877
INCLUDE P16F877.INC ;INCLUDE REGISTER DEFINITION FILE
INCLUDE test.inc ; module definition file
; ================
; Reset vector
STARTUP CODE 0x0000
RESET:
NOP ;REQUIRED BY ICD
PAGESEL beginning
GOTO beginning ;INITIALIZE PROCESSOR AFTER RESET
shared_stuff UDATA_shr ; Let linker allocate space for these.
ISR_W res 1 ; must be in a ``global'' register or in every page at
the same offset.
idle_count res 4
endtime res 2
; 16 bit return value from read_timer1().
TMPH res 1
TMPL res 1
beginning CODE
beginning:
BCF INTCON,7 ;GLOBALLY DISABLE INTERRUPTS
BTFSC INTCON,7 ;BRANCH IF INTERRUPTS ARE DISABLED
GOTO RESET ;ELSE, TRY TO DISABLE AGAIN
MAINLP:
; [FIXME: do something useful here]
CALL times1.5
GOTO MAINLP
END
; end file main.asm
--
http://www.piclist.com#nomail Going offline? Don't AutoReply us!
email spam_OUTlistservTakeThisOuT
mitvma.mit.edu with SET PICList DIGEST in the body
2001\04\05@214139
by
Bill Westfield
Assemblers are generally less flexible with things like symbols and scoping
than the average high level language...
Unfortunately, I seem to get a lot of errors like
Error[115] C:\DAVID\GRAPHI~1\LCD_CO~1\TEST.ASM 4 : Duplicate label
("times1.5" or redefining symbol that cannot be redefined)
This happens when your code contains the equivilent of:
EXTERN times1.5
times1.5: ;code (note times1.5 symbol is defined here.)
right? (sorry about the tabs, Olin :-) I suspect that having declared
that the symbol is external, the assembler doesn't want to see it defined
internally... Your next examble tries to address exactly that issue:
GLOBAL times1.5
times1.5: ;code (note times1.5 symbol is defined here.)
and you get the complaint:
Error[113] C:\DAVID\GRAPHI~1\LCD_CO~1\MAIN.ASM 38 : Symbol not previously
defined (times1.5)
I conclude here that the assmebler doesn't want to make a symbol global
until after that symbol has been defined, ie it wants:
times1.5: GLOBAL times1.5
; code
Or something similar. (Note that this is all guesses.) If your included
file contains only global/external definitions, you'd want it at the END
of the code rather than at the beginning... It also looks like you'll have
problems using the standard C practice of using the same include file for
all your source modules...
You might want to check what the defaults are for an assembler. An
assembler I used to use would automatically treat unresolved symbols as
external, but required a special declaration to get symbols to be accessable
form outside the module ("Intern", IIRC. (as opposed to local?) Go figure.)
random symbols defined in a module were local ("static" in C parlance)
unless specifically marked otherwise. There were also special operators
that set symbols to various scopes at the time they were defined, ie:
label1:: ; globally accessable label
label2: ; local (per source module) label.
I'm not that familiar with the PIC assemblers, but there may be similar
capabilities...
BillW
--
http://www.piclist.com#nomail Going offline? Don't AutoReply us!
email .....listservKILLspam
@spam@mitvma.mit.edu with SET PICList DIGEST in the body
2001\04\06@081330
by
Olin Lathrop
> I seem to get some kind of error no matter how I tweak my ``test.inc''
file. If
> I replace ``EXTERN'' with ``GLOBAL'' in that file, I get
> Error[113] C:\DAVID\GRAPHI~1\LCD_CO~1\MAIN.ASM 38 : Symbol not
previously
> defined (times1.5)
> Error[113] C:\DAVID\GRAPHI~1\LCD_CO~1\TEST.INC 17 : Symbol not
previously
> defined (ACC0)
Don't put EXTERN and GLOBAL in include files. For an example, see
http://www.embedinc.com/pic and check out the HAL project. This is a
multi-module project with a common include file. This page also contains
template files for a whole project.
********************************************************************
Olin Lathrop, embedded systems consultant in Littleton Massachusetts
(978) 742-9014, olin
KILLspamembedinc.com, http://www.embedinc.com
--
http://www.piclist.com hint: To leave the PICList
.....piclist-unsubscribe-requestKILLspam
.....mitvma.mit.edu
2001\04\07@111543
by
Douglas Wood
Actually, David, now that I'm fully awake... ;-)
Put "GLOBAL TIMES1.5" in TEST.ASM and "EXTERN TIMES1.5" in MAIN.ASM.
Remember GLOBAL exports the label to other modules and EXTERN says that the
label is external to the current module.
Douglas Wood
Software Engineer
EraseMEdbwoodspam_OUT
TakeThisOuTkc.rr.com
Home of the EPICIS Development System for the PIC and SX
http://www.piclist.com/techref/member/DW--RA4
{Original Message removed}
2001\04\07@144725
by
Douglas Wood
David,
1) Your label "times1.5", although it's only defined once (as a label in
TEST.ASM), appears in TEST.INC in an EXTERN statement. You have #included
TEST.INC proper in TEST.ASM, but you also #include it in MAIN.ASM. There is
no label "times1.5" that appears in MAIN.ASM. I think you misunderstand the
purpose for using an #include file. Typically, EXTERN statement should be in
the file where the label appears and no where else.
2) For the label ACC0, see above.
Douglas Wood
Software Engineer
dbwood
spam_OUTkc.rr.com
Home of the EPICIS Development System for the PIC and SX
http://www.piclist.com/techref/member/DW--RA4
{Original Message removed}
'[PIC]: MPASM include files'
2001\05\23@105417
by
David Cary
|
Dear PIC programmers,
William Chops Westfield <@spam@billwKILLspam
cisco.com> on 2001-04-05 08:41:21 PM
made some comments that led me to do a little experimentation. Along with the
explaination from Douglas Wood, I've learned how to break programs up into
several files and get them to compile, link together, and run without error.
(Well, without syntax errors anyway).
Douglas Wood <KILLspamdbwoodKILLspam
KC.RR.COM> on 2001-04-07 10:08:26 AM mentioned
> You have #included TEST.INC proper in TEST.ASM, but you also #include it in
MAIN.ASM.
Yes. That is the ``C Way''.
I'm used to the ``C Way'' of breaking up a program into several files, as
explained in the C FAQ:
http://www.faqs.org/faqs/C-faq/faq/
<blockquote>
1.7: What's the best way to declare and define global variables
and functions?
A: First, though there can be many "declarations" (and in many
translation units) of a single "global" (strictly speaking,
"external") variable or function, there must be exactly one
"definition". (The definition is the declaration that actually
allocates space, and provides an initialization value, if any.)
The best arrangement is to place each definition in some
relevant .c file, with an external declaration in a header
(".h") file, which is #included wherever the declaration is
needed. The .c file containing the definition should also
#include the same header file, so that the compiler can check
that the definition matches the declarations.
</blockquote>
>I think you misunderstand the purpose for using an #include file.
I think not. :-)
I have some subroutines in one file (test.asm) that I want to call from another
file (main.asm). The assembler needs to know that, both when it is compiling
test.asm, and also when it is calling main.asm.The header file lists those
subroutines. That is the purpose of the header file.
At least, that is how things are done in C. What's the right way to do it in
assembly ?
>Put "GLOBAL TIMES1.5" in TEST.ASM and "EXTERN TIMES1.5" in MAIN.ASM.
>Remember GLOBAL exports the label to other modules and EXTERN says that the
>label is external to the current module.
Ah. This works for me. Thanks. I didn't know that before.
Olin Lathrop <RemoveMEolin_piclistTakeThisOuT
EMBEDINC.COM> on 2001-04-06 06:29:56 AM suggested:
> Don't put EXTERN and GLOBAL in include files. For an example, see
> http://www.embedinc.com/pic and check out the HAL project. This is a
> multi-module project with a common include file. This page also contains
> template files for a whole project.
Many people use a single common include file, and that works for them. I've been
trained differently. I put related subroutines together in one file (of type
``.c'' or ``.asm''). Then I make a corresponding header file with the same name
(of type ``.h'' or ``.inc'') that lists those subroutines, plus some English
text on how to call the subroutines and what they do. This makes it easier for
me to re-use that group of subroutines in a completely different project. I
don't make *any* changes to that ``.asm'' file, nor to its associated ``.inc''
file; I just add the ``include __.inc'' line to my new ``main.asm'' file, and
start calling those subroutines from within that ``main.asm'' file.
--
David Cary
--
http://www.piclist.com hint: The list server can filter out subtopics
(like ads or off topics) for you. See http://www.piclist.com/#topics
More... (looser matching)
- Last day of these posts
- In 2001
, 2002 only
- Today
- New search...