I must be missing something simple...
I have a relocatable assembly project. I have one main.asm file. It is 15,000 lines of code. I would like to take some of my subroutines and put them in their own files. I have a subroutine "_CheckBatt". Is uses one register "BATTERY", defined in direct page "BATTERY DS 1".
Why can I not just copy the entire subroutine, from "_CheckBatt:" to "RTS" into it's own .asm file? I tried putting "XREF BATTERY" and "XREFB BATTERY" at the top of "_CheckBatt.asm". I made sure to put "INCLUDE '_CheckBatt.asm'" at the top of "main.asm". I even tried putting "XDEF BATTERY" at the top of "main.asm". The compiler keeps saying something like "variable redefined".
Shouldn't using multiple files be simple?
Is it a matter of XDEF and XREF? Or maybe .asm vs .inc files? How about relocatable SECTION vs absolute ORG? As long as the registers are defined in RAM, why does it matter if it is ORG or not?
How about a simple example of two file, "main.asm" and "second.asm" (or "second.inc") that shows main defining a register "TEST DS 1", using a "JSR" instruction to jump into a subroutine in the "second" file, and that subroutine in the "second" files manipulates "TEST", and then calls "RTS"...
Thanks in advance!!!
-Mike
Hi Michael,
Attached you will find an example mixing C and Asm file.
This will help you to understand how the XDEF/XREF is working.
XDEF is used to define a variable in the asm module whereas the XREF is used to say the varialbe is defined in another module which could be .c or .asm
The example files show you how the directives must be used.
Relocatable project is using a prm file to allocate the memory.
The absolute project can be used if your application contains 1 asm file only.
In this case the ORG is used to define the memory address.
The attached example is using CW for MCU V6.3 (Classic version).
Have a great day,
Pascal Irrle
-----------------------------------------------------------------------------------------------------------------------
Note: If this post answers your question, please click the Correct Answer button. Thank you!
-----------------------------------------------------------------------------------------------------------------------
Helpful. I have it working.
Next question, again, thanks in advance...
I have a variable/register defined in main.asm as "FOO DS 1" and it's after an "ORG ZRAM_Start" for zero page. This is all great and fine and everything is perfect. Now that I can use multiple files, I have a separate file "test.asm". At the top of test.asm I have "FOO DS 1" (no ORG statement). This essentially is creating a "local" varibale/register "FOO" that it used in test.asm, BUT DOES NOT CHANGE "FOO" IN main.asm CORRECT? I have tested this is true, but my REAL question is: WHERE IS THIS "NEW/LOCAL" "FOO" ACTUALLY BEING CREATED IN RAM? Who decides that and how? I am using all 1024 bytes of RAM so I DO NOT want this new/local "FOO" to be just created some random place in RAM, overwriting/change a value that is already there.
I hope some light can be shed on this. Thanks again!!
Michael,
There are several ways to create your assembly project.
If you want to use the default startup function and able to add some C code in future you can create a mixed project which included .c and .asm files.
If you want to use asm code only you can create this project too.
In both case a prm file is used to allocated code and ram in memory.
The object codes generated with the assembler and compiler contain some information used by the linker to correctly allocated memory.
If in your code, a variable is not defined to an existing memory segment defined in prm, the linker will place it in DEFAULT_RAM.
If in your code, a function is not defined to an existing memory segment defined in prm, the linker will place it in DEFAULT_ROM.
The allocation can be done via ORG or via SECTION for instance:
MY_ZEROPAGE: SECTION SHORT | ; Insert here your data definition |
fiboCount DS.W 1
counter: | DS.B 1 |
These 2 variables will be associated in the MY_ZEROPAGE section.
If this section is defined in prm (this is the case), the variables will be placed in this memory area.
If this section is not listed in the prm, the variables will be placed in DEFAULT_RAM by default.
If an assembly variable is not exported with XREF/XDEF, the variable will be available for the asm module only.
If the same variable is defined in x asm file, the variables will use x memory locations.
So we can say each variable will be as "Local" one very similar to static variable in C.
You could find some information in the Assembler_HC08.pdf manual in the folder: \CodeWarrior for Microcontrollers V6.3\Help\PDF
Attached you will find a new example based on Fibonacci code in asm.
With a linker option you can generate a map file which will give you all memory allocation information.
This option is -M.
Have a great day,
Pascal Irrle
-----------------------------------------------------------------------------------------------------------------------
Note: If this post answers your question, please click the Correct Answer button. Thank you!
-----------------------------------------------------------------------------------------------------------------------