Macro in Assembler HCS12

取消
显示结果 
显示  仅  | 搜索替代 
您的意思是: 

Macro in Assembler HCS12

1,832 次查看
Molibdeno
Contributor II

Good day
I am trying to use a microcontroller HCS12
I have a module built in Assembler, and I would like to automatically exchange the "BRA" and "LBRA" command on assembler code
I built this macro in which it should automatically recognize if the jump distance is too big for the BRA command.

MyBRA macro
   if ( \1 < (*)+256)
       BRA \1
   else
       LBRA \1
   endif
endm

Unfortunately the compiler shows me an error on line "if( \1 <(*)+256)" : "A2314 expression must be absolute"
Is there a method in assembler to make this macro work? ... or another method that works
My purpose is to make the assembler decide whether to use LBRA or BRA

Thanks to all

0 项奖励
回复
3 回复数

1,810 次查看
ZhangJennie
NXP TechSupport
NXP TechSupport

Hi

You have error A2314. This error description.

An absolute expression is expected at the specified position. Assembler directives expecting an absolute value are: OFFSET, ORG, ALIGN, SET, BASE, DS, LLEN, PLEN, SPC, TABS, IF, IFEQ, IFNE, IFLE, IFLT, IFGE, IFGT. The first operand in a DCB directive must be absolute:
Example:
DataSec: SECTION
label1:  DS.W 1
label2:  DS.W 2
label3:  EQU  8

codeSec: SECTION

         BASE label1

         ALIGN label2

Tips

Specify an absolute expression at the specified position.

Example

DataSec: SECTION
label1:  DS.W 1
label2:  DS.W 2
label3:  EQU  8

codeSec: SECTION

         BASE label3

         ALIGN 4
0 项奖励
回复

1,787 次查看
Molibdeno
Contributor II

Thanks ZhangJennie ....To simplify everything ..... I tried to create new project ... a small example of testing in "relocable assembler":

main.asm:

; Include derivative-specific definitions
INCLUDE 'derivative.inc'
; export symbols
XDEF Entry, _Startup, main

XREF __SEG_END_SSTACK ; symbol defined by the linker for the end of the stack

MyBRA macro
if (\1<(*+256))
BRA \1
else
LBRA \1
endif
endm

; variable/data section
MY_EXTENDED_RAM: SECTION
Counter ds.w 1

; code section
MyCode: SECTION
main:
_Startup:
Entry:
LDS #__SEG_END_SSTACK ; initialize the stack pointer
EndlessLoop:
LDX #1 ; X contains counter
CouterLoop:
STX Counter ; update global.
LDX Counter
INX
CPX #24 ; larger values cause overflow.
BNE CouterLoop
MyBRA EndlessLoop ; restart.                              ;<<<<<<<<<<<<<<<< My macro <<<<<<<<

 

Unfortunately now it gives me a different mistake

A2401:Complex relocable expression not supported

Macro Expression "if(EndlessLoop <* + 256)"

 

0 项奖励
回复

1,784 次查看
ZhangJennie
NXP TechSupport
NXP TechSupport

Hi Molibdeno 

Please follow this tips to fix error

Description

A complex relocatable expression has been detected. A complex relocatable expression is detected when the expression contains:
  • An operation between labels located in two different sections.
  • A multiplication, division or modulo operation between two labels.
  • The addition of two labels located in the same section.

Example

          XDEF offset
DataSec1: SECTION SHORT
DataLbl1: DS.B 10
DataSec2: SECTION SHORT
DataLbl2: DS.W 15
offset:   EQU DataLbl2 - DataLbl1

Tips

The macro assembler does not support complex relocatable expressions. The corresponding expression must be evaluated at execution time.

If both DataSec1 and DataSec2 are in the same section and defined in this module, the assembler can compute the difference:

DataSec1: SECTION SHORT
DataLbl1: DS.B 10
DataLbl2: DS.W 15
offset:   EQU DataLbl2 - DataLbl1

Have a nice day

Jun Zhang

0 项奖励
回复