EmbeddedRelated.com
Forums

IAR assembler -- use of a constant and $ in an expression

Started by Jon Kirwan September 20, 2009
On Mon, 21 Sep 2009 07:27:40 +0930, you wrote:

>Hi Jon, sorry if I'm responsible for returning your sanity, I personally
>feel much better off without mine! I'd lay odds it's a compiler issue,
>but you're certainly more than welcome to the mild assist.

Well... I'm still having problems. Set up a workspace, select the
MSP430F149 as the target. Mark the project as "assembler only," of
course. I'm not linking any library, either. Select the simulator
instead of a FET Tool (just in case.)

(I used the generic #include in the code below. I believe it selects
the appropriate include file for the specific processor.)

#include "msp430.h"

NAME main
PUBLIC main
ORG 0FFFEh
DC16 init
RSEG CSTACK
RSEG CODE
init: MOV #SFE(CSTACK), SP ; set up stack
MOV.W #WDTPW+WDTHOLD,&WDTCTL ; stop watchdog
main:
add #$, r15
add #-$, r15
add #(0-$), r15
add #(2-$), r15
add #($-0), r15
add #($-2), r15
add #-($-2), r15
me EQU $
add #(0x0002-me), r15
JMP $

END

Then move into the simulator and open up a disassembly window and look
at the binary word values loaded there. Compare.

I'm still getting the same issue with 4.20.1 (4.20.1.50017).

Thanks in advance,
Jon

Beginning Microcontrollers with the MSP430

Hi Jon,
This is what I do when I start a new project.

Open the workspace.
Create a new project
make it asm only
Go back into the workspace and delete the IAR provided asm shell file
then roll in my own simple shell file which basically looks like thast
below. This may seem pedantic, but i got into the habit years ago when I
found that such simple things saved me from getting files all crossed up
whenever I tried to upgrade IAR. It works, it's a minor inconvenience. i
don't tend to use SEGMENT assignments, i don't need to, or want to, I
prefer to manage all of that myself, I don't need, nor ever expect to
need to write relocatable code, or anything else which might require me
to trust a program to manage any of my memory for me, therefore I see no
need to mess with that. #include and the occasional ORG or EVEN is all
I need to manage memory allocation and keep things straight.

i wouldn't make any assumptions about what #include "msp430.h" does. I
would rather be specific. Also I tend to modify the header files to
include other information I find valuable, and to drop all the stuff I
find superfluous. i aslo make my own comments, which i find more
meaningful,bELOW THIS IS THE LISTING FROM MY OWN ATTEMPT AT A RAW SIMPLE
ASM FILE USING MSP430.H
#include "MSP430F2131.H" ;Hardware Register definitions
#include "ULOG_HDR.S43" ;Constants, variables and flags
#include "ULOG_MAIN.S43" ;Constants, variables and flags
#include "ULOG_INIT.S43"
#include "ULOG_ICC.S43"
#include "ULOG_UART.S43"
#include "FLASH.S43"

;****************************************************************************
;*
;* Interrupt Vector Assignments
;*
;****************************************************************************

ORG INT_TABLE ;Start of Int Table

INTERRUPT_VECTORS:
DW DUMMY_VECTOR
DW DUMMY_VECTOR
DW PORT1_VECTOR /* 0xFFE4 Port 1 */
DW PORT2_VECTOR /* 0xFFE6 Port 2 */
DW DUMMY_VECTOR
DW DUMMY_VECTOR
DW DUMMY_VECTOR
DW DUMMY_VECTOR
DW TIMERA1_VECTOR /* 0xFFF0 Timer A CC1-2, TA */
DW TIMERA0_VECTOR /* 0xFFF2 Timer A CC0 */
DW WDT_VECTOR /* 0xFFF4 Watchdog Timer */
DW COMPARATORA_VECTOR /* 0xFFF6 Comparator A */
DW DUMMY_VECTOR
DW DUMMY_VECTOR
DW NMI_VECTOR /* 0xFFFC Non-maskable */
DW RESET_VECTOR /* 0xFFFE Reset [Highest Priority] */
;****************************************************************************

END
;****************************************************************************

*****************************************************************************
/////////////////////////////////////////////////////////////////////////////

BELOW here I took the IAR default asm file then scrubbed the segment
stuff, because it appears to be setting the PC to FFFe with the ORG
statement. I then tried to compile and the MOV #SFE(CSTACK) ,SP was
giving an error, so I just replaced it, as it's really irrelevant to the
aim, anyway clean up the asm shell and it compiles as expected.

3 001000 ORG 1000H
4 001000
5 001000 JONTEST:
6 001000 3F500010 add.w #$, r15 ; 1. expected
7 001004 3F50FCEF add.w #-$, r15 ; 2. expected
8 001008 3F50F8EF add.w #(0-$), r15 ; 3. not expected
9 00100C 3F50F6EF add.w #(2-$), r15 ; 4. not expected
10 001010 3F501010 add.w #($-0), r15 ; 5. expected
11 001014
12 001014
13 001014
14 00E000 ORG 0E000H
15 00E000 31400003 init: MOV #0x0300, SP ; set up
stack
16 00E004
17 00E004 0343 main: NOP
; main

program
18 00E006 B240805A2001 MOV.W #WDTPW+WDTHOLD,&WDTCTL
; Stop

watchdo
g

timer
19 00E00C FF3F JMP $
; jump
to current location '$'

20 00E00E END
Cheers

AL

Jon Kirwan wrote:
> On Mon, 21 Sep 2009 07:27:40 +0930, you wrote:
>
>> Hi Jon, sorry if I'm responsible for returning your sanity, I personally
>> feel much better off without mine! I'd lay odds it's a compiler issue,
>> but you're certainly more than welcome to the mild assist.
>
> Well... I'm still having problems. Set up a workspace, select the
> MSP430F149 as the target. Mark the project as "assembler only," of
> course. I'm not linking any library, either. Select the simulator
> instead of a FET Tool (just in case.)
>
> (I used the generic #include in the code below. I believe it selects
> the appropriate include file for the specific processor.)
>
> #include "msp430.h"
>
> NAME main
> PUBLIC main
> ORG 0FFFEh
> DC16 init
> RSEG CSTACK
> RSEG CODE
> init: MOV #SFE(CSTACK), SP ; set up stack
> MOV.W #WDTPW+WDTHOLD,&WDTCTL ; stop watchdog
> main:
> add #$, r15
> add #-$, r15
> add #(0-$), r15
> add #(2-$), r15
> add #($-0), r15
> add #($-2), r15
> add #-($-2), r15
> me EQU $
> add #(0x0002-me), r15
> JMP $
>
> END
>
> Then move into the simulator and open up a disassembly window and look
> at the binary word values loaded there. Compare.
>
> I'm still getting the same issue with 4.20.1 (4.20.1.50017).
>
> Thanks in advance,
> Jon
>
On Mon, 21 Sep 2009 09:22:54 +0930, you wrote:

>Hi Jon,
> This is what I do when I start a new project.

Gotcha, Al. One issue I want to clarify, before saying more. I note
that you use ORG 1000H. I'm intentionally attempting to do this with
relocatable segment code. It's important that the actual location be
deferred until link time. If you could, would you consider using
whatever methods you use for relocatable segments on this? Or do you
use them, at all?

(This all relates to some experiments with the c compiler.)

Jon
On Sun, 20 Sep 2009 21:36:55 +0000, you wrote:

> Hi Al, you got it. I was testing using a program I made and it was
>starting at 0x9000, that resulted in the Error 446. Moving the start
>to 0x1100 did solve it.
> Then I also did a try with:
> add.w #2-$,r15
> add.w#(2-$),r15
> In both cases the assembler did calculate correctly.
> As you pointed out device type seems to be the issue since Jons
>experiments where also in lower memory.
> My target device is '149.

I get fully understandable results when I apply an ORG statement. But
this tells the assembler, prior to the link process, where things are
located. I'm exploring the link process with relocatable segments and
without specifying an ORG.

For example, asm81.s43 (complete source, below) produces results I
completely embrace and understand. However, with a very slight
modification to it, merely changing the ASEG to an RSEG, it produces
entirely different code for some of the instructions. And if you
comment out the ORG after that, again different but still not what I'd
expect.

I am struggling with this, a bit. I imagine there is a linker file --
it's called lnk430f149.xcl -- and the memory areas it sets up are:

// Peripheral units: 0 - 01FF
// Information memory (FLASH): 1000 - 10FF
// Read-write memory (RAM): 0200 - 09FF
// Read-only memory (FLASH): 1100 - FFDF

No surprise, really.

Anyway. Wish this made sense, right now.

Thanks very much to all,
Jon

P.S. I stuffed the start vector segment at the bottom and used ENDMOD
to isolate the two modules from each other, despite being in the same
source file. Just to keep that ORG down below, in the source, rather
than up above where some (me, too) may be confused by its presence.

......asm81.s43.....

#include "msp430x14x.h"

NAME main
PUBLIC init
RSEG CSTACK
ASEG CODE ; <--- note ASEG, not RSEG
ORG 1100H ; <--- note ORG used
init: mov #SFE(CSTACK), SP ; set up stack
mov.w #WDTPW+WDTHOLD,&WDTCTL ; stop watchdog
main:
add #$, r15
add #-$, r15
add #(0-$), r15
add #(2-$), r15
add #($-0), r15
add #($-2), r15
add #-($-2), r15
me EQU $
add #(0x0002-me), r15
jmp $
ENDMOD

NAME startvector
EXTERN init
ORG 0FFFEh
DC16 init

END

....................