Archived

This topic is now archived and is closed to further replies.

Assembly

This topic is 5378 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hello All The following is the example of the inline assembly code I got from the web. which get the value of A7 address register and put it in temp. Then temp can be used as a normal C varible My question is that how can I do the opposit eg. copy the value in temp and put it in A7 please help Thanks asm("move.l %%a7, %0" : "=d" (temp) : ); current_proc->user_stack = temp;

Share this post


Link to post
Share on other sites
Doesn't this work ?


asm( "move.l %0, %%a7"
:
: "d" (temp)
: "a7" // if you want a7 to be saved & restored
);


See this page. It is not extremely clear, but that's all the documentation I am aware of on inline assembly in gcc.


[ Start Here ! | How To Ask Smart Questions | Recommended C++ Books | C++ FAQ Lite | Function Ptrs | CppTips Archive ]
[ Header Files | File Format Docs | LNK2001 | C++ STL Doc | STLPort | Free C++ IDE | Boost C++ Lib | MSVC6 Lib Fixes ]


[edited by - Fruny on March 23, 2003 4:42:16 PM]

Share this post


Link to post
Share on other sites
quote:
Original post by Tiger99
should I use %7 instead of %%7?



%7 should refer to the 8th ''formal'' operand, just like %0 here refers to the first ''formal'' operand, that is the variable ''temp''.

There is a second page, I''m looking at it right now.

More info if I find or understand any


[ Start Here ! | How To Ask Smart Questions | Recommended C++ Books | C++ FAQ Lite | Function Ptrs | CppTips Archive ]
[ Header Files | File Format Docs | LNK2001 | C++ STL Doc | STLPort | Free C++ IDE | Boost C++ Lib | MSVC6 Lib Fixes ]

Share this post


Link to post
Share on other sites
Actually, your best bet if you have a full GNU environment is to look at the info pages for gas in addition to the gcc inline assembly ones.

The page on the Motorola 68k confirms %a7 ... that's the CPU you're using, right ?

note - messing up a6 or a7 is usually a *bad* idea, since they are the frame and stack pointers respectively.


[ Start Here ! | How To Ask Smart Questions | Recommended C++ Books | C++ FAQ Lite | Function Ptrs | CppTips Archive ]
[ Header Files | File Format Docs | LNK2001 | C++ STL Doc | STLPort | Free C++ IDE | Boost C++ Lib | MSVC6 Lib Fixes ]


[edited by - Fruny on March 23, 2003 4:59:24 PM]

Share this post


Link to post
Share on other sites
I am not sure
My Teaching assistant told me that I could find the answer in the following documentation
http://gcc.gnu.org/onlinedocs/gcc-2.95.3/gcc_4.html

but I have problem understanding most of the part

Share this post


Link to post
Share on other sites
quote:
Original post by Tiger99
http://gcc.gnu.org/onlinedocs/gcc-2.95.3/gcc_4.html



That''s where I''ve been pulling the doc from (except from the 3.2 version instead of the 2.95 one).

I''ll decompose the statement you''ve been using :

asm( // opcodes
"mov.l %a7, %0" // Move (mov)
// 32 bits (.l)
// from register a7 (%a7)
// to operand #0 (%0)
: // formal output operands
"=d" (temp) // operand #0 is write only (=)
// operand #0 is in a data register (d)
// operand #0 is the C variable ''temp'' ((temp))
: // formal input operands
// none
);


The compiler is free to choose any data register to put ''temp'' in.

Share this post


Link to post
Share on other sites
Hello
I am getting an unknown register name a7 in asm
How could I solve this problem?

please help

Thanks
VOID initialization(VOID)
{
int sr;
/* Disable all interupts */
asm( "move.w #0x2700,%sr" );
coldfire_vbr_init();
//Initialize PCB
initialize_pcb();
sr = NullPCB[254];
asm( "move.l %0, %%a7" : : "d" (sr) : "a7" // if you want a7 to be saved & restored
);
asm("rte");
/* enable interrupt */
asm( "move.w #0x2000,%sr" );
}

Share this post


Link to post
Share on other sites
Since you haven't confirmed whether you were using a M68K processor - which has an A7 register - I cannot answer that question. Look at the gas info page for what register your CPU does provide. You can also try taking out the : "a7" part, because, the way you're using it, the whole statement is a no-op.




[ Start Here ! | How To Ask Smart Questions | Recommended C++ Books | C++ FAQ Lite | Function Ptrs | CppTips Archive ]
[ Header Files | File Format Docs | LNK2001 | C++ STL Doc | STLPort | Free C++ IDE | Boost C++ Lib | MSVC6 Lib Fixes ]


[edited by - Fruny on March 23, 2003 7:00:55 PM]

Share this post


Link to post
Share on other sites
I am using M68K, I took off the a7 but it compiles. However, I am getting
Illegal stack type! and
Access Error: FS=C, Physical bus error on operand read

errors after I download to the coldfire board
How can I fix the problems?

Thanks

Share this post


Link to post
Share on other sites
Look a few posts up. A7 is the stack pointer. If you write meaningless values to it, you can expect your program to crash on function return.

I cannot fix this problem for you.


[ Start Here ! | How To Ask Smart Questions | Recommended C++ Books | C++ FAQ Lite | Function Ptrs | CppTips Archive ]
[ Header Files | File Format Docs | LNK2001 | C++ STL Doc | STLPort | Free C++ IDE | Boost C++ Lib | MSVC6 Lib Fixes ]

Share this post


Link to post
Share on other sites
1) the direction of the move is incorrect if the comments are correct - to save the SSP, a7 needs to be on the left. The code as it stands moves from the sr variable into a7 which re-writes the SSP with the value in that variable.


2) it pays to be explicit, if you mean SSP rather than USP, use SSP (assuming your assembler supports the proper names for the registers).


3) That code will only work when the CPU is in supervisor mode, since there's an RTE in there I'll assume the code is started from a trap or IRQ which is ok. But don't call that code from user mode, say with a jsr.


4) the rte returns from the function - so the re-enable interrupts line should be BEFORE that!


5) where does that code return to? - if you need to return somewhere surely you should have a couple of "movem"s in there to save the current registers - particularly because the C code is likely to trash other registers.


6) moving 7 into the interrupt status bits of the SSR will prevent the interrupt from the CPUs point of view - depending on your hardware there may be more work required to also disable the source of the interrupts.


7) The 680x0 CPU requires the address for any long/word read/writes must be on an even address or you'll get a privilege violation.


8) Is NullPCB intended to be your new stack?, if so:

a. that move.l should be an "lea" to get the address of that rather than the value. Alternatively the address should be prefixed with a #

b. the address needs to be at the _end_ of the memory for your stack (just to make sure that the value is)

c. bear in mind that C and C++ use tons more stackspace than handcoded assembly - if that's 255 bytes, then IMO it's too small


--
Simon O'Connor
Creative Asylum Ltd
www.creative-asylum.com

[edited by - s1ca on March 23, 2003 7:48:44 PM]

Share this post


Link to post
Share on other sites