Atmel website | ARM Community | AVR freaks | Technical Support
Banner
 FAQ •  Search •  Register •  Login 

All times are UTC + 1 hour [ DST ]




Post new topic Reply to topic  [ 4 posts ] 
Author Message
 Post subject: porting SAM-BA applet to IAR
PostPosted: Thu Nov 17, 2011 7:12 pm 
Offline

Joined: Tue Jun 30, 2009 11:44 am
Posts: 7
Hi everyone,

I'm trying to port the SAM-BA applet project to work with IAR compiler instead of GCC.
Now, I have one assembly line that I don't know how to convert to IAR.

The relevant line is:
add r1, pc,#-(8+.-mailbox)

And the whole context is:
/* Branch to main()
******************/
mov r0, #1
add r1, pc,#-(8+.-mailbox)
ldr r3, =?main
mov lr, pc
bx r3

When the mailbox define as:
mailbox:
DS32 4*32

Thanks for your help!

Zohar


Top
 Profile  
 
 Post subject: Re: porting SAM-BA applet to IAR
PostPosted: Thu Nov 17, 2011 7:51 pm 
Offline

Joined: Sat Oct 30, 2010 6:04 pm
Posts: 574
R0 is Param#1 = 1
R1 is Param#2 = &mailbox

It's the address of the mailbox, in a location independent fashion, so it doesn't matter where SAM-BA loads the applet, and fills the mailbox structure.

Something like this is viable in Keil, IAR would probably be similar. In Keil/GCC '.' is the assemblers program counter, the use of '*' or '$' is common in other assemblers.

here ADD R1, PC, #-(here + 8 - mailbox)

If IAR won't do the math for you, then you could always use a hard coded constant offset.


Top
 Profile  
 
 Post subject: Re: porting SAM-BA applet to IAR
PostPosted: Thu Nov 17, 2011 11:55 pm 
Offline

Joined: Tue Jun 30, 2009 11:44 am
Posts: 7
Hi CptTitanic,

Many thanks for fast reply.

Your explanation is clear to me except one thing:
What is "-(here + 8 - mailbox)"

I can't find any sense in that arithmetic...

Let's say mailbox adder is 0x301108 and PC on the relevant line is 0x301314. What then should be the second parameter of the main function?

Thanks in advance

Zohar
BTW, if this project will work I'll be happy to share it with the forum members.


Top
 Profile  
 
 Post subject: Re: porting SAM-BA applet to IAR
PostPosted: Fri Nov 18, 2011 4:40 pm 
Offline

Joined: Sat Oct 30, 2010 6:04 pm
Posts: 574
The math is based on the fact the ARM is pipelined, the value read from PC in a computation will be 8 bytes ahead of the instruction that is executing.

When entering main(), R1 = 0x301108, the address is computed in an agnostic manner so that it doesn't matter what address the code is physically loaded or mapped. Other architectures would use 'LEA', Load Effective Address, but the ARM doesn't have that, so an equivalent is utilized.

00301108 mailbox
..
00301314 sub r1, pc, #0x214 ; r1 = pc - 0x214


-(0x301314 + 8 - 0x301108)
-(0x30131C - 0x301108)
-(0x214)

So PC + -(0x214) is better encoded as PC - 0x214, so the assembler typically will reverse the ADD and use the SUB variant automatically.


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 4 posts ] 

All times are UTC + 1 hour [ DST ]


Who is online

Users browsing this forum: No registered users and 3 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to: