Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What does '__asm__(".previous");' mean?

While trying to compile my project, that uses some third party headers, with mingw 4.4, I encountered the following error:

Assembler messages:
Error: junk at end of line, first unrecognized character is '"'
Error: unknown pseudo-op: '.previous'

I found this code at the end of one of the included headers:

__asm__(".section \".plc\"");
__asm__(".previous");

Since I do not have any experience at all with in-line assembler instructions, I googled for an explanation to it, but couldn't find the answer to my two basic questions. What does __asm__(".previous"); acctually do and why would anyone put this at the end of a header file.

These are the only __asm__ instructions in the whole project. Can I safely delete them? Or is there a way to define .previous in order to make it a known pseudo-op?

Enlighten me, please!

like image 609
NullAndVoid Avatar asked Mar 10 '10 12:03

NullAndVoid


1 Answers

.previous is a directive that lets you swap back and forth between two elf sections. It is a shortcut that allows denser assembly files and lets you for example declare initialized data within a stream of code or vice versa.

For example say you have an assembler file with a data and a code section.

If you want - in the middle of a function - declare a constant in the data segment you can use the .previous statement like this:

  nop            // some code

.previous        // swaps current section (code) with previous section (data)

MyConstant:
  .word 0x0001   // some data

.previous        // swaps curent section (data) with previous section (code)

  nop            // more code

More information can be found in the reference manual:

http://sourceware.org/binutils/docs-2.19/as/Previous.html#Previous

like image 88
Nils Pipenbrinck Avatar answered Oct 14 '22 16:10

Nils Pipenbrinck