How to define local various using HCS08 Assembly language

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

How to define local various using HCS08 Assembly language

1,821 Views
Tianshu
Contributor I

Hi, I'm a beginner of Freescale MCU. I'm confusing how to define local various and use it using HCS08 assembly language. Can someone give me some examples? Thanks.

Labels (1)
0 Kudos
6 Replies

681 Views
xtronics
Contributor I

I know what you mean - local scope such as within a subroutine.  Some assemblers use a special prefix to the label and delimit the scope by a double  ** at the beginning of a line (like a subroutine header has).   That way you can use ?loop as a label any number of times in your program.

 

I looked around quite a bit - seems their assembler doesn't support it. (or they have it confused with the scope of a macro.)

 

 It would be nice if someone at freescale commented on this issue.  There is still a lot of work that belongs in assembly language and local labels are not something we should have to live without. (the assembler X68C11.EXE had them)..

 

The other thing I miss is a block comment macro in codewarrior 10.0..  The docs imply it is there - but I can't get it to work.

 

 

0 Kudos

681 Views
bigmac
Specialist III

Hello,

 

Assuming you have a relocatable assembly project, all labels are limited to file scope anyway.  To increase beyond this requires specific use of the directives XDEF to export a label name from a file, and XREF to import a label name into a file.

 

A label occurring within a macro will be local to each use of the macro.

 

But I guess you already know this.  Having never used an assembler that provided local variables with sub-routine scope (the P&E assemblers I have used also did not have this facility), I have never felt the specific need.

 

Perhaps this assembler might have the extra bells and whistles that you require.

 

Regards,

Mac

 

0 Kudos

681 Views
CrasyCat
Specialist III

Hello

 

What are you trying to achieve here exactly?

 

If the question is how to make sure the assembler generates unique labels inside of macros, refer to HC08 assembler manual chapter Macro >Labels inside macros.

 

If you are using CW V10.x the manual is located in {Install}\MCU\\Help\PDF and is called HCS08-RS08_Assembler_MCU_Eclipse.pdf.

If you are using V6.x or earlier, the manual is located in {Install}\Help\PDF and is called Assembler_HC08.pdf.

 

If you want to simulate local variables on the stack this is not directly supported by the assembler, but you can modify stack pointer using instruction AIS and then use the OFFSET assembler directive to associate symbolic names to stack location.

 

You can get an example of OFFSET directive in the assembler manual specified above.

  

I hope this helps.

 

CrasyCat

0 Kudos

681 Views
xtronics
Contributor I

It isn't about within macros. 

 

I'm wondering if there is any problem using a different assembler from within codewarrior?  ASM8 supports local labels.

 

 

Here is an example of what we are talking about:

 

 

 

** header line that starts with two splats limits the scope?loop   inca        bne ?loop** next subroutine?loop incx bne ?loop

 

 

The reuse of ?loop is not a problem for most assembler and makes the code more readable than trying to invent hundreds of labels.

 

The choice of  **  and ? is sometimes configurable.

 

 

 

 

 

0 Kudos

681 Views
CrasyCat
Specialist III

No you cannot use another assembler within CodeWarrior,

 

CrasyCat

0 Kudos

681 Views
bigmac
Specialist III

Hello,

 

I assume that you wish to define some variables within RAM.  I do not know what you actually mean by "local" - the stack can be used for temporary storage of intermediate values within a sub-routine, but I will assume this is not what you want to do in this case.

 

To define a number of bytes of RAM storage at a specific location, you will need to make use of the DS directive.  Other variations are DS.B, DS.W and DS.L to explicitly define byte, word (16-bit) or long (32-bit) variable size.  Some examples are given in the Assembler manual.

 

Regards,

Mac

 

0 Kudos