ADS1.2 inline assembly :Branching by writing PC is not supported

Hello, I got into trouble when learning ADS 1.2 inline assembly.

I create a project as arm executable image in default settings. It contains only one file : main.c

void main(void){

__asm { mov pc,0x0 } }

When i compiled this project , i got the error :

Warning : C2865W: extern 'main' needs to be 'int' function: 'int' assumed main.c line 1 Error : (Serious) C2044E: branching by writing PC is not supported main.c line 6 C:\main.c: 1 warning, 0 errors, 1 serious error

I google and find this file "

formatting link
" it says "C2044E: branching by writing PC is not supported. Illegal inline assembly instruction consult the ARM ARM for the allowed forms. "

Then I have a looked at arm architecture reference manual , but nothing helps.

I think maybe ADS1.2 compiler doesn't support this kinds of syntax. But how can I achieve the goal like this ?

Anybody help ,pls ? Thanks!

Reply to
Zhenhuan Du
Loading thread data ...

I'm guessing that the compiler doesn't like it because it can't analyze the control flow anymore.

Instead of using in-line assembly, you can make a separate .asm file, and implement the code in there.

Or, simply use C instead:

((void (*) ()) 0)();

Reply to
Arlet

You should read the ADS manual/docs. (I guess they can be found on

formatting link
The inline asm in ADS is not quite pure asm, it is being compiled by the ADS and there's a number of restrictions. IIRC, you can't work with the PC or SP directly, and more.... But, as you've already been advised, you can use any opcodes in a separate .asm file if you want to.

Reply to
tum_

Yep, here's the one to read on inline asm (and much more):

formatting link

and lots of other stuff under

formatting link

Reply to
tum_

Really appreciate your great help :) More in detail: I'm porting following code to ADS project: //some C codes here asm volatile ( "MOV r1, %5\n\t" "MOV r2, %6\n\t" "MOV r3, %7\n\t" "MOV LR, PC\n\t" "MOV PC, %4\n\t" "MOV %0, r0\n\t" "MOV %1, r1\n\t" "MOV %2, r2\n\t" "MOV %3, r3\n\t" : "=&r" (bRetCode), "=&r" (wExtension), "=&r" (dLastOffset), "=&r" (wNextInst) : "r" (AnfNS), "r" (pSegTab_l), "r" (pAdrHS), "r" (pAdrDS) : "r0", "r1", "r2", "r3" );

//some C codes here Can you tell the compiler used from the top instruction format ? They are quite different form ADS compiler's instruction format. Can you give me some advice on this porting regarding to "writing to PC"?

Reply to
Zhenhuan Du

Zhenhuan Du napisa?(a):

For me it seams to be GCC inline assemble.

Regards AK

Reply to
AK

Well, this is definitely GCC's inline assembly, it has its unique syntax as far as I'm aware. You will have to be creative a bit to port this to ADS because I don't think you can do it by just changing the syntax. In ADS the inline asm does not allow certain things and you'll have to work around those restrictions. ( It's my late evening after a hectic working day and I simply can't grasp what this code might be doing but the gut feeling is - make sure you need any asm here at all...)

Reply to
tum_

It's modifying the link and program counter registers part way through so it cannot execute straight line. It rather looks like an attempt to create the most obscure context switch possible.

On a rewrite I'd strongly encourage rewriting in assembler rather than trying to use inline assembler for it.

Robert

--
Posted via a free Usenet account from http://www.teranews.com
Reply to
Robert Adsett

That is the jmp instruction. A relative jump is done by performing arithmetic on the PC.

Robert

--
Posted via a free Usenet account from http://www.teranews.com
Reply to
Robert Adsett

I'd say that is rather a 'call' instruction. They save the PC into LR prior to modifying the PC. Anyway, Wilco has produced the C equivalent of this code that looks correct. I'm just wondering what the AnfNS() function is doing, is it also written in assembly?

Reply to
tum_

Good point. Although the form above is jusy a jmp ;)

Robert

--
Posted via a free Usenet account from http://www.teranews.com
Reply to
Robert Adsett

oh, absolutely. I was, of course, referring to another code snippet that disappeared from the quotes...

(I'm posting from google and I always have to struggle with quotes).

Reply to
tum_

ElectronDepot website is not affiliated with any of the manufacturers or service providers discussed here. All logos and trade names are the property of their respective owners.